diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 1d6627987e151..b5a0619430788 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -13,11 +13,26 @@ namespace ts { referenced: boolean; } - export function getModuleInstanceState(node: ModuleDeclaration): ModuleInstanceState { - return node.body ? getModuleInstanceStateWorker(node.body) : ModuleInstanceState.Instantiated; + export function getModuleInstanceState(node: ModuleDeclaration, visited?: Map): ModuleInstanceState { + if (node.body && !node.body.parent) { + // getModuleInstanceStateForAliasTarget needs to walk up the parent chain, so parent pointers must be set on this tree already + setParentPointers(node, node.body); + } + return node.body ? getModuleInstanceStateCached(node.body, visited) : ModuleInstanceState.Instantiated; } - function getModuleInstanceStateWorker(node: Node): ModuleInstanceState { + function getModuleInstanceStateCached(node: Node, visited = createMap()) { + const nodeId = "" + getNodeId(node); + if (visited.has(nodeId)) { + return visited.get(nodeId) || ModuleInstanceState.NonInstantiated; + } + visited.set(nodeId, undefined); + const result = getModuleInstanceStateWorker(node, visited); + visited.set(nodeId, result); + return result; + } + + function getModuleInstanceStateWorker(node: Node, visited: Map): ModuleInstanceState { // A module is uninstantiated if it contains only switch (node.kind) { // 1. interface declarations, type alias declarations @@ -37,11 +52,27 @@ namespace ts { return ModuleInstanceState.NonInstantiated; } break; - // 4. other uninstantiated module declarations. + // 4. Export alias declarations pointing at only uninstantiated modules or things uninstantiated modules contain + case SyntaxKind.ExportDeclaration: + if (!(node as ExportDeclaration).moduleSpecifier && !!(node as ExportDeclaration).exportClause) { + let state = ModuleInstanceState.NonInstantiated; + for (const specifier of (node as ExportDeclaration).exportClause!.elements) { + const specifierState = getModuleInstanceStateForAliasTarget(specifier, visited); + if (specifierState > state) { + state = specifierState; + } + if (state === ModuleInstanceState.Instantiated) { + return state; + } + } + return state; + } + break; + // 5. other uninstantiated module declarations. case SyntaxKind.ModuleBlock: { let state = ModuleInstanceState.NonInstantiated; forEachChild(node, n => { - const childState = getModuleInstanceStateWorker(n); + const childState = getModuleInstanceStateCached(n, visited); switch (childState) { case ModuleInstanceState.NonInstantiated: // child is non-instantiated - continue searching @@ -61,7 +92,7 @@ namespace ts { return state; } case SyntaxKind.ModuleDeclaration: - return getModuleInstanceState(node as ModuleDeclaration); + return getModuleInstanceState(node as ModuleDeclaration, visited); case SyntaxKind.Identifier: // Only jsdoc typedef definition can exist in jsdoc namespace, and it should // be considered the same as type alias @@ -72,6 +103,36 @@ namespace ts { return ModuleInstanceState.Instantiated; } + function getModuleInstanceStateForAliasTarget(specifier: ExportSpecifier, visited: Map) { + const name = specifier.propertyName || specifier.name; + let p: Node | undefined = specifier.parent; + while (p) { + if (isBlock(p) || isModuleBlock(p) || isSourceFile(p)) { + const statements = p.statements; + let found: ModuleInstanceState | undefined; + for (const statement of statements) { + if (nodeHasName(statement, name)) { + if (!statement.parent) { + setParentPointers(p, statement); + } + const state = getModuleInstanceStateCached(statement, visited); + if (found === undefined || state > found) { + found = state; + } + if (found === ModuleInstanceState.Instantiated) { + return found; + } + } + } + if (found !== undefined) { + return found; + } + } + p = p.parent; + } + return ModuleInstanceState.Instantiated; // Couldn't locate, assume could refer to a value + } + const enum ContainerFlags { // The current node is not a container, and no container manipulation should happen before // recursing into it. @@ -2561,7 +2622,7 @@ namespace ts { // Declare a 'member' if the container is an ES5 class or ES6 constructor constructorSymbol.members = constructorSymbol.members || createSymbolTable(); // It's acceptable for multiple 'this' assignments of the same identifier to occur - declareSymbol(constructorSymbol.members, constructorSymbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); + declareSymbol(constructorSymbol.members, constructorSymbol, node, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); addDeclarationToSymbol(constructorSymbol, constructorSymbol.valueDeclaration, SymbolFlags.Class); } break; @@ -2575,7 +2636,7 @@ namespace ts { // Bind this property to the containing class const containingClass = thisContainer.parent; const symbolTable = hasModifier(thisContainer, ModifierFlags.Static) ? containingClass.symbol.exports! : containingClass.symbol.members!; - declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property, SymbolFlags.None, /*isReplaceableByMethod*/ true); + declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property | SymbolFlags.Assignment, SymbolFlags.None, /*isReplaceableByMethod*/ true); break; case SyntaxKind.SourceFile: // this.property = assignment in a source file -- declare symbol in exports for a module, in locals for a script diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f180f9e544b6a..e245ca8aa2622 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1030,7 +1030,11 @@ namespace ts { function mergeSymbol(target: Symbol, source: Symbol, unidirectional = false): Symbol { if (!(target.flags & getExcludedSymbolFlags(source.flags)) || (source.flags | target.flags) & SymbolFlags.Assignment) { - Debug.assert(source !== target); + if (source === target) { + // This can happen when an export assigned namespace exports something also erroneously exported at the top level + // See `declarationFileNoCrashOnExtraExportModifier` for an example + return target; + } if (!(target.flags & SymbolFlags.Transient)) { const resolvedTarget = resolveSymbol(target); if (resolvedTarget === unknownSymbol) { @@ -1520,8 +1524,8 @@ namespace ts { isInExternalModule = true; // falls through case SyntaxKind.ModuleDeclaration: - const moduleExports = getSymbolOfNode(location as SourceFile | ModuleDeclaration).exports!; - if (location.kind === SyntaxKind.SourceFile || isAmbientModule(location)) { + const moduleExports = getSymbolOfNode(location as SourceFile | ModuleDeclaration).exports || emptySymbols; + if (location.kind === SyntaxKind.SourceFile || (isModuleDeclaration(location) && location.flags & NodeFlags.Ambient && !isGlobalScopeAugmentation(location))) { // It's an external module. First see if the module has an export default and if the local // name of that export default matches. @@ -2203,7 +2207,7 @@ namespace ts { function getTargetOfNamespaceImport(node: NamespaceImport, dontResolveAlias: boolean): Symbol | undefined { const moduleSpecifier = node.parent.parent.moduleSpecifier; - return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias); + return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier, dontResolveAlias, /*suppressUsageError*/ false); } // This function creates a synthetic symbol that combines the value side of one symbol with the @@ -2257,9 +2261,10 @@ namespace ts { function getExternalModuleMember(node: ImportDeclaration | ExportDeclaration, specifier: ImportOrExportSpecifier, dontResolveAlias = false): Symbol | undefined { const moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier!)!; // TODO: GH#18217 - const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier!, dontResolveAlias); + const name = specifier.propertyName || specifier.name; + const suppressInteropError = name.escapedText === InternalSymbolName.Default && !!(compilerOptions.allowSyntheticDefaultImports || compilerOptions.esModuleInterop); + const targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier!, dontResolveAlias, suppressInteropError); if (targetSymbol) { - const name = specifier.propertyName || specifier.name; if (name.escapedText) { if (isShorthandAmbientModuleSymbol(moduleSymbol)) { return moduleSymbol; @@ -2321,17 +2326,37 @@ namespace ts { function getTargetOfExportAssignment(node: ExportAssignment | BinaryExpression, dontResolveAlias: boolean): Symbol | undefined { const expression = (isExportAssignment(node) ? node.expression : node.right) as EntityNameExpression | ClassExpression; + return getTargetOfAliasLikeExpression(expression, dontResolveAlias); + } + + function getTargetOfAliasLikeExpression(expression: Expression, dontResolveAlias: boolean) { if (isClassExpression(expression)) { - return checkExpression(expression).symbol; + return checkExpressionCached(expression).symbol; + } + if (!isEntityName(expression) && !isEntityNameExpression(expression)) { + return undefined; } const aliasLike = resolveEntityName(expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ true, dontResolveAlias); if (aliasLike) { return aliasLike; } - checkExpression(expression); + checkExpressionCached(expression); return getNodeLinks(expression).resolvedSymbol; } + function getTargetOfPropertyAssignment(node: PropertyAssignment, dontRecursivelyResolve: boolean): Symbol | undefined { + const expression = node.initializer; + return getTargetOfAliasLikeExpression(expression, dontRecursivelyResolve); + } + + function getTargetOfPropertyAccessExpression(node: PropertyAccessExpression, dontRecursivelyResolve: boolean): Symbol | undefined { + if (!(isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === SyntaxKind.EqualsToken)) { + return undefined; + } + + return getTargetOfAliasLikeExpression(node.parent.right, dontRecursivelyResolve); + } + function getTargetOfAliasDeclaration(node: Declaration, dontRecursivelyResolve = false): Symbol | undefined { switch (node.kind) { case SyntaxKind.ImportEqualsDeclaration: @@ -2349,6 +2374,12 @@ namespace ts { return getTargetOfExportAssignment((node), dontRecursivelyResolve); case SyntaxKind.NamespaceExportDeclaration: return getTargetOfNamespaceExportDeclaration(node, dontRecursivelyResolve); + case SyntaxKind.ShorthandPropertyAssignment: + return resolveEntityName((node as ShorthandPropertyAssignment).name, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, /*ignoreErrors*/ true, dontRecursivelyResolve); + case SyntaxKind.PropertyAssignment: + return getTargetOfPropertyAssignment(node as PropertyAssignment, dontRecursivelyResolve); + case SyntaxKind.PropertyAccessExpression: + return getTargetOfPropertyAccessExpression(node as PropertyAccessExpression, dontRecursivelyResolve); default: return Debug.fail(); } @@ -2712,7 +2743,7 @@ namespace ts { function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol { if (moduleSymbol) { const exportEquals = resolveSymbol(moduleSymbol.exports!.get(InternalSymbolName.ExportEquals), dontResolveAlias); - const exported = getCommonJsExportEquals(exportEquals, moduleSymbol); + const exported = getCommonJsExportEquals(getMergedSymbol(exportEquals), getMergedSymbol(moduleSymbol)); return getMergedSymbol(exported) || moduleSymbol; } return undefined!; @@ -2722,26 +2753,31 @@ namespace ts { if (!exported || exported === unknownSymbol || exported === moduleSymbol || moduleSymbol.exports!.size === 1 || exported.flags & SymbolFlags.Alias) { return exported; } - const merged = cloneSymbol(exported); + const links = getSymbolLinks(exported); + if (links.cjsExportMerged) { + return links.cjsExportMerged; + } + const merged = exported.flags & SymbolFlags.Transient ? exported : cloneSymbol(exported); + merged.flags = merged.flags | SymbolFlags.ValueModule; if (merged.exports === undefined) { - merged.flags = merged.flags | SymbolFlags.ValueModule; merged.exports = createSymbolTable(); } moduleSymbol.exports!.forEach((s, name) => { if (name === InternalSymbolName.ExportEquals) return; merged.exports!.set(name, merged.exports!.has(name) ? mergeSymbol(merged.exports!.get(name)!, s) : s); }); - return merged; + getSymbolLinks(merged).cjsExportMerged = merged; + return links.cjsExportMerged = merged; } // An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export =' // references a symbol that is at least declared as a module or a variable. The target of the 'export =' may // combine other declarations with the module or variable (e.g. a class/module, function/module, interface/variable). - function resolveESModuleSymbol(moduleSymbol: Symbol | undefined, referencingLocation: Node, dontResolveAlias: boolean): Symbol | undefined { + function resolveESModuleSymbol(moduleSymbol: Symbol | undefined, referencingLocation: Node, dontResolveAlias: boolean, suppressInteropError: boolean): Symbol | undefined { const symbol = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias); if (!dontResolveAlias && symbol) { - if (!(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable)) && !getDeclarationOfKind(symbol, SyntaxKind.SourceFile)) { + if (!suppressInteropError && !(symbol.flags & (SymbolFlags.Module | SymbolFlags.Variable)) && !getDeclarationOfKind(symbol, SyntaxKind.SourceFile)) { const compilerOptionName = moduleKind >= ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; @@ -2982,7 +3018,8 @@ namespace ts { */ function getContainersOfSymbol(symbol: Symbol, enclosingDeclaration: Node | undefined): Symbol[] | undefined { const container = getParentOfSymbol(symbol); - if (container) { + // Type parameters end up in the `members` lists but are not externally visible + if (container && !(symbol.flags & SymbolFlags.TypeParameter)) { const additionalContainers = mapDefined(container.declarations, fileSymbolIfFileSymbolExportEqualsContainer); const reexportContainers = enclosingDeclaration && getAlternativeContainingModules(symbol, enclosingDeclaration); if (enclosingDeclaration && getAccessibleSymbolChain(container, enclosingDeclaration, SymbolFlags.Namespace, /*externalOnly*/ false)) { @@ -2991,7 +3028,18 @@ namespace ts { const res = append(additionalContainers, container); return concatenate(res, reexportContainers); } - const candidates = mapDefined(symbol.declarations, d => !isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent) ? getSymbolOfNode(d.parent) : undefined); + const candidates = mapDefined(symbol.declarations, d => { + if (!isAmbientModule(d) && d.parent && hasNonGlobalAugmentationExternalModuleSymbol(d.parent)) { + return getSymbolOfNode(d.parent); + } + if (isClassExpression(d) && isBinaryExpression(d.parent) && d.parent.operatorToken.kind === SyntaxKind.EqualsToken && isAccessExpression(d.parent.left) && isEntityNameExpression(d.parent.left.expression)) { + if (isModuleExportsPropertyAccessExpression(d.parent.left) || isExportsIdentifier(d.parent.left.expression)) { + return getSymbolOfNode(getSourceFileOfNode(d)); + } + checkExpressionCached(d.parent.left.expression); + return getNodeLinks(d.parent.left.expression).resolvedSymbol; + } + }); if (!length(candidates)) { return undefined; } @@ -3000,7 +3048,7 @@ namespace ts { function fileSymbolIfFileSymbolExportEqualsContainer(d: Declaration) { const fileSymbol = getExternalModuleContainer(d); const exported = fileSymbol && fileSymbol.exports && fileSymbol.exports.get(InternalSymbolName.ExportEquals); - return resolveSymbol(exported) === resolveSymbol(container) ? fileSymbol : undefined; + return exported && container && getSymbolIfSameReference(exported, container) ? fileSymbol : undefined; } } @@ -3009,21 +3057,30 @@ namespace ts { // fast path, `symbol` is either already the alias or isn't aliased return symbol; } + // Check if container is a thing with an `export=` which points directly at `symbol`, and if so, return + // the container itself as the alias for the symbol + const exportEquals = container.exports && container.exports.get(InternalSymbolName.ExportEquals); + if (exportEquals && getSymbolIfSameReference(exportEquals, symbol)) { + return container; + } const exports = getExportsOfSymbol(container); const quick = exports.get(symbol.escapedName); - if (quick && symbolRefersToTarget(quick)) { + if (quick && getSymbolIfSameReference(quick, symbol)) { return quick; } return forEachEntry(exports, exported => { - if (symbolRefersToTarget(exported)) { + if (getSymbolIfSameReference(exported, symbol)) { return exported; } }); + } - function symbolRefersToTarget(s: Symbol) { - if (s === symbol || resolveSymbol(s) === symbol || resolveSymbol(s) === resolveSymbol(symbol)) { - return s; - } + /** + * Checks if two symbols, through aliasing and/or merging, refer to the same thing + */ + function getSymbolIfSameReference(s1: Symbol, s2: Symbol) { + if (getMergedSymbol(resolveSymbol(getMergedSymbol(s1))) === getMergedSymbol(resolveSymbol(getMergedSymbol(s2)))) { + return s1; } } @@ -3142,7 +3199,32 @@ namespace ts { } // falls through case SyntaxKind.ModuleDeclaration: - if (result = callback(getSymbolOfNode(location as ModuleDeclaration).exports!)) { + const sym = getSymbolOfNode(location as ModuleDeclaration); + // `sym` may not have exports if this module declaration is backed by the symbol for a `const` that's being rewritten + // into a namespace - in such cases, it's best to just let the namespace appear empty (the const members couldn't have referred + // to one another anyway) + if (result = callback(sym.exports || emptySymbols)) { + return result; + } + break; + case SyntaxKind.ClassDeclaration: + case SyntaxKind.ClassExpression: + case SyntaxKind.InterfaceDeclaration: + // Type parameters are bound into `members` lists so they can merge across declarations + // This is troublesome, since in all other respects, they behave like locals :cries: + // TODO: the below is shared with similar code in `resolveName` - in fact, rephrasing all this symbol + // lookup logic in terms of `resolveName` would be nice + // The below is used to lookup type parameters within a class or interface, as they are added to the class/interface locals + // These can never be latebound, so the symbol's raw members are sufficient. `getMembersOfNode` cannot be used, as it would + // trigger resolving late-bound names, which we may already be in the process of doing while we're here! + let table: UnderscoreEscapedMap | undefined; + // TODO: Should this filtered table be cached in some way? + (getSymbolOfNode(location as ClassLikeDeclaration | InterfaceDeclaration).members || emptySymbols).forEach((memberSymbol, key) => { + if (memberSymbol.flags & (SymbolFlags.Type & ~SymbolFlags.Assignment)) { + (table || (table = createSymbolTable())).set(key, memberSymbol); + } + }); + if (table && (result = callback(table))) { return result; } break; @@ -3190,12 +3272,12 @@ namespace ts { } function isAccessible(symbolFromSymbolTable: Symbol, resolvedAliasSymbol?: Symbol, ignoreQualification?: boolean) { - return symbol === (resolvedAliasSymbol || symbolFromSymbolTable) && + return (symbol === (resolvedAliasSymbol || symbolFromSymbolTable) || getMergedSymbol(symbol) === getMergedSymbol(resolvedAliasSymbol || symbolFromSymbolTable)) && // if the symbolFromSymbolTable is not external module (it could be if it was determined as ambient external module and would be in globals table) // and if symbolFromSymbolTable or alias resolution matches the symbol, // check the symbol can be qualified, it is only then this symbol is accessible !some(symbolFromSymbolTable.declarations, hasNonGlobalAugmentationExternalModuleSymbol) && - (ignoreQualification || canQualifySymbol(symbolFromSymbolTable, meaning)); + (ignoreQualification || canQualifySymbol(getMergedSymbol(symbolFromSymbolTable), meaning)); } function trySymbolTable(symbols: SymbolTable, ignoreQualification: boolean | undefined): Symbol[] | undefined { @@ -3587,6 +3669,8 @@ namespace ts { withContext(enclosingDeclaration, flags, tracker, context => symbolToParameterDeclaration(symbol, context)), typeParameterToDeclaration: (parameter: TypeParameter, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker) => withContext(enclosingDeclaration, flags, tracker, context => typeParameterToDeclaration(parameter, context)), + symbolTableToDeclarationStatements: (symbolTable: SymbolTable, enclosingDeclaration?: Node, flags?: NodeBuilderFlags, tracker?: SymbolTracker, bundled?: boolean) => + withContext(enclosingDeclaration, flags, tracker, context => symbolTableToDeclarationStatements(symbolTable, context, bundled)), }; function withContext(enclosingDeclaration: Node | undefined, flags: NodeBuilderFlags | undefined, tracker: SymbolTracker | undefined, cb: (context: NodeBuilderContext) => T): T | undefined { @@ -3749,6 +3833,7 @@ namespace ts { return createInferTypeNode(typeParameterToDeclarationWithConstraint(type as TypeParameter, context, /*constraintNode*/ undefined)); } if (context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams && + type.flags & TypeFlags.TypeParameter && !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration)) { const name = typeParameterToName(type, context); context.approximateLength += idText(name).length; @@ -3982,6 +4067,8 @@ namespace ts { else if (context.flags & NodeBuilderFlags.WriteClassExpressionAsTypeLiteral && type.symbol.valueDeclaration && isClassLike(type.symbol.valueDeclaration) && + // Use `import` types for refs to other scopes, only anonymize something defined in the same scope + findAncestor(type.symbol.valueDeclaration, d => d === getSourceFileOfNode(context.enclosingDeclaration)) && !isValueSymbolAccessible(type.symbol, context.enclosingDeclaration) ) { return createAnonymousTypeNode(type); @@ -4149,11 +4236,7 @@ namespace ts { const methodDeclaration = signatureToSignatureDeclarationHelper(signature, SyntaxKind.MethodSignature, context); methodDeclaration.name = propertyName; methodDeclaration.questionToken = optionalToken; - if (propertySymbol.valueDeclaration) { - // Copy comments to node for declaration emit - setCommentRange(methodDeclaration, propertySymbol.valueDeclaration); - } - typeElements.push(methodDeclaration); + typeElements.push(preserveCommentsOn(methodDeclaration)); } } else { @@ -4179,11 +4262,22 @@ namespace ts { propertyTypeNode, /*initializer*/ undefined); - if (propertySymbol.valueDeclaration) { + typeElements.push(preserveCommentsOn(propertySignature)); + } + + function preserveCommentsOn(node: T) { + if (some(propertySymbol.declarations, d => d.kind === SyntaxKind.JSDocPropertyTag)) { + const d = find(propertySymbol.declarations, d => d.kind === SyntaxKind.JSDocPropertyTag)! as JSDocPropertyTag; + const commentText = d.comment; + if (commentText) { + setSyntheticLeadingComments(node, [{ kind: SyntaxKind.MultiLineCommentTrivia, text: "*\n * " + commentText.replace(/\n/g, "\n * ") + "\n ", pos: -1, end: -1, hasTrailingNewLine: true }]); + } + } + else if (propertySymbol.valueDeclaration) { // Copy comments to node for declaration emit - setCommentRange(propertySignature, propertySymbol.valueDeclaration); + setCommentRange(node, propertySymbol.valueDeclaration); } - typeElements.push(propertySignature); + return node; } } @@ -4369,6 +4463,10 @@ namespace ts { function lookupSymbolChain(symbol: Symbol, context: NodeBuilderContext, meaning: SymbolFlags, yieldModuleSymbol?: boolean) { context.tracker.trackSymbol!(symbol, context.enclosingDeclaration, meaning); // TODO: GH#18217 + return lookupSymbolChainWorker(symbol, context, meaning, yieldModuleSymbol); + } + + function lookupSymbolChainWorker(symbol: Symbol, context: NodeBuilderContext, meaning: SymbolFlags, yieldModuleSymbol?: boolean) { // Try to get qualified name if the symbol is not a type parameter and there is an enclosing declaration. let chain: Symbol[]; const isTypeParameter = symbol.flags & SymbolFlags.TypeParameter; @@ -4401,6 +4499,13 @@ namespace ts { for (const parent of sortedParents) { const parentChain = getSymbolChain(parent, getQualifiedLeftMeaning(meaning), /*endOfChain*/ false); if (parentChain) { + if (parent.exports && parent.exports.get(InternalSymbolName.ExportEquals) && + getSymbolIfSameReference(parent.exports.get(InternalSymbolName.ExportEquals)!, symbol)) { + // parentChain root _is_ symbol - symbol is a module export=, so it kinda looks like it's own parent + // No need to lookup an alias for the symbol in itself + accessibleSymbolChain = parentChain; + break; + } accessibleSymbolChain = parentChain.concat(accessibleSymbolChain || [getAliasForSymbolInContainer(parent, symbol) || symbol]); break; } @@ -4592,17 +4697,33 @@ namespace ts { const typeParameterNodes = index === (chain.length - 1) ? overrideTypeArguments : lookupTypeParameterNodes(chain, index, context); const symbol = chain[index]; + const parent = chain[index - 1]; + let symbolName: string | undefined; if (index === 0) { context.flags |= NodeBuilderFlags.InInitialEntityName; - } - const symbolName = getNameOfSymbolAsWritten(symbol, context); - context.approximateLength += symbolName.length + 1; - if (index === 0) { + symbolName = getNameOfSymbolAsWritten(symbol, context); + context.approximateLength += (symbolName ? symbolName.length : 0) + 1; context.flags ^= NodeBuilderFlags.InInitialEntityName; } + else { + if (parent && getExportsOfSymbol(parent)) { + const exports = getExportsOfSymbol(parent); + forEachEntry(exports, (ex, name) => { + if (getSymbolIfSameReference(ex, symbol) && !isLateBoundName(name) && name !== InternalSymbolName.ExportEquals) { + symbolName = unescapeLeadingUnderscores(name); + return true; + } + }); + } + } + if (!symbolName) { + symbolName = getNameOfSymbolAsWritten(symbol, context); + } + context.approximateLength += symbolName.length + 1; - const parent = chain[index - 1]; - if (!(context.flags & NodeBuilderFlags.ForbidIndexedAccessSymbolReferences) && parent && getMembersOfSymbol(parent) && getMembersOfSymbol(parent).get(symbol.escapedName) === symbol) { + if (!(context.flags & NodeBuilderFlags.ForbidIndexedAccessSymbolReferences) && parent && + getMembersOfSymbol(parent) && getMembersOfSymbol(parent).get(symbol.escapedName) && + getSymbolIfSameReference(getMembersOfSymbol(parent).get(symbol.escapedName)!, symbol)) { // Should use an indexed access const LHS = createAccessFromSymbolChain(chain, index - 1, stopper); if (isIndexedAccessTypeNode(LHS)) { @@ -4639,6 +4760,9 @@ namespace ts { } } let result = symbolToName(type.symbol, context, SymbolFlags.Type, /*expectsIdentifier*/ true); + if (!(result.kind & SyntaxKind.Identifier)) { + return createIdentifier("(Missing type parameter)"); + } if (context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams) { const rawtext = result.escapedText as string; let i = 0; @@ -4735,6 +4859,1198 @@ namespace ts { } } } + + // See getNameForSymbolFromNameType for a stringy equivalent + function getPropertyNameNodeForSymbolFromNameType(symbol: Symbol, context: NodeBuilderContext) { + const nameType = symbol.nameType; + if (nameType) { + if (nameType.flags & TypeFlags.StringOrNumberLiteral) { + const name = "" + (nameType).value; + if (!isIdentifierText(name, compilerOptions.target) && !isNumericLiteralName(name)) { + return createLiteral(name); + } + if (isNumericLiteralName(name) && startsWith(name, "-")) { + return createComputedPropertyName(createLiteral(+name)); + } + return isIdentifierText(name, compilerOptions.target) ? createIdentifier(name) : createLiteral(isNumericLiteralName(name) ? +name : name) as StringLiteral | NumericLiteral; + } + if (nameType.flags & TypeFlags.UniqueESSymbol) { + return createComputedPropertyName(symbolToExpression((nameType).symbol, context, SymbolFlags.Value)); + } + } + } + + function cloneNodeBuilderContext(context: NodeBuilderContext): NodeBuilderContext { + const initial: NodeBuilderContext = { ...context }; + // Make type parameters created within this context not consume the name outside this context + // The symbol serializer ends up creating many sibling scopes that all need "separate" contexts when + // it comes to naming things - within a normal `typeToTypeNode` call, the node builder only ever descends + // through the type tree, so the only cases where we could have used distinct sibling scopes was when there + // were multiple generic overloads with similar generated type parameter names + // The effect: + // When we write out + // export const x: (x: T) => T + // export const y: (x: T) => T + // we write it out like that, rather than as + // export const x: (x: T) => T + // export const y: (x: T_1) => T_1 + if (initial.typeParameterNames) { + initial.typeParameterNames = cloneMap(initial.typeParameterNames); + } + if (initial.typeParameterNamesByText) { + initial.typeParameterNamesByText = cloneMap(initial.typeParameterNamesByText); + } + if (initial.typeParameterSymbolList) { + initial.typeParameterSymbolList = cloneMap(initial.typeParameterSymbolList); + } + return initial; + } + + function symbolTableToDeclarationStatements(symbolTable: SymbolTable, context: NodeBuilderContext, bundled?: boolean): Statement[] { + const serializePropertySymbolForClass = makeSerializePropertySymbol(createProperty, SyntaxKind.MethodDeclaration); + const serializePropertySymbolForInterfaceWorker = makeSerializePropertySymbol((_decorators, mods, name, question, type, initializer) => createPropertySignature(mods, name, question, type, initializer), SyntaxKind.MethodSignature); + + // TODO: Use `setOriginalNode` on original declaration names where possible so these declarations see some kind of + // declaration mapping + + // We save the enclosing declaration off here so it's not adjusted by well-meaning declaration + // emit codepaths which want to apply more specific contexts (so we can still refer to the root real declaration + // we're trying to emit from later on) + const enclosingDeclaration = context.enclosingDeclaration!; + let results: Statement[] = []; + const visitedSymbols: Map = createMap(); + let deferredPrivates: Map | undefined; + const oldcontext = context; + context = { + ...oldcontext, + usedSymbolNames: mapMap(symbolTable, (_symbol, name) => [unescapeLeadingUnderscores(name), true]), + remappedSymbolNames: createMap(), + tracker: { + ...oldcontext.tracker, + trackSymbol: (sym, decl, meaning) => { + const accessibleResult = isSymbolAccessible(sym, decl, meaning, /*computeALiases*/ false); + if (accessibleResult.accessibility === SymbolAccessibility.Accessible) { + // Lookup the root symbol of the chain of refs we'll use to access it and serialize it + const chain = lookupSymbolChainWorker(sym, context, meaning); + if (!(sym.flags & SymbolFlags.Property)) { + includePrivateSymbol(chain[0]); + } + } + else if (oldcontext.tracker && oldcontext.tracker.trackSymbol) { + oldcontext.tracker.trackSymbol(sym, decl, meaning); + } + } + } + }; + if (oldcontext.usedSymbolNames) { + oldcontext.usedSymbolNames.forEach((_, name) => { + context.usedSymbolNames!.set(name, true); + }); + } + let addingDeclare = !bundled; + const exportEquals = symbolTable.get(InternalSymbolName.ExportEquals); + if (exportEquals && symbolTable.size > 1 && exportEquals.flags & SymbolFlags.Alias) { + symbolTable = createSymbolTable(); + // Remove extraneous elements from root symbol table (they'll be mixed back in when the target of the `export=` is looked up) + symbolTable.set(InternalSymbolName.ExportEquals, exportEquals); + } + + visitSymbolTable(symbolTable); + return mergeRedundantStatements(results); + + function isIdentifierAndNotUndefined(node: Node | undefined): node is Identifier { + return !!node && node.kind === SyntaxKind.Identifier; + } + + function getNamesOfDeclaration(statement: Statement): Identifier[] { + if (isVariableStatement(statement)) { + return filter(map(statement.declarationList.declarations, getNameOfDeclaration), isIdentifierAndNotUndefined); + } + return filter([getNameOfDeclaration(statement as DeclarationStatement)], isIdentifierAndNotUndefined); + } + + function flattenExportAssignedNamespace(statements: Statement[]) { + const exportAssignment = find(statements, isExportAssignment); + const ns = find(statements, isModuleDeclaration); + if (ns && exportAssignment && exportAssignment.isExportEquals && + isIdentifier(exportAssignment.expression) && isIdentifier(ns.name) && idText(ns.name) === idText(exportAssignment.expression) && + ns.body && isModuleBlock(ns.body)) { + // Pass 0: Correct situations where a module has both an `export = ns` and multiple top-level exports by stripping the export modifiers from + // the top-level exports and exporting them in the targeted ns, as can occur when a js file has both typedefs and `module.export` assignments + const excessExports = filter(statements, s => !!(getModifierFlags(s) & ModifierFlags.Export)); + if (length(excessExports)) { + ns.body.statements = createNodeArray([...ns.body.statements, createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamedExports(map(flatMap(excessExports, e => getNamesOfDeclaration(e)), id => createExportSpecifier(/*alias*/ undefined, id))), + /*moduleSpecifier*/ undefined + )]); + } + + + // Pass 1: Flatten `export namespace _exports {} export = _exports;` so long as the `export=` only points at a single namespace declaration + if (!find(statements, s => s !== ns && nodeHasName(s, ns.name as Identifier))) { + results = []; + forEach(ns.body.statements, s => { + addResult(s, ModifierFlags.None); // Recalculates the ambient (and export, if applicable from above) flag + }); + statements = [...filter(statements, s => s !== ns && s !== exportAssignment), ...results]; + } + } + return statements; + } + + function mergeExportDeclarations(statements: Statement[]) { + // Pass 2: Combine all `export {}` declarations + const exports = filter(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration[]; + if (length(exports) > 1) { + const nonExports = filter(statements, d => !isExportDeclaration(d) || !!d.moduleSpecifier || !d.exportClause); + statements = [...nonExports, createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamedExports(flatMap(exports, e => e.exportClause!.elements)), + /*moduleSpecifier*/ undefined + )]; + } + // Pass 2b: Also combine all `export {} from "..."` declarations as needed + const reexports = filter(statements, d => isExportDeclaration(d) && !!d.moduleSpecifier && !!d.exportClause) as ExportDeclaration[]; + if (length(reexports) > 1) { + const groups = group(reexports, decl => isStringLiteral(decl.moduleSpecifier!) ? ">" + decl.moduleSpecifier.text : ">"); + if (groups.length !== reexports.length) { + for (const group of groups) { + if (group.length > 1) { + // remove group members from statements and then merge group members and add back to statements + statements = [ + ...filter(statements, s => group.indexOf(s as ExportDeclaration) === -1), + createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamedExports(flatMap(group, e => e.exportClause!.elements)), + group[0].moduleSpecifier + ) + ]; + } + } + } + } + return statements; + } + + function inlineExportModifiers(statements: Statement[]) { + // Pass 3: Move all `export {}`'s to `export` modifiers where possible + const exportDecl = find(statements, d => isExportDeclaration(d) && !d.moduleSpecifier && !!d.exportClause) as ExportDeclaration | undefined; + if (exportDecl) { + const replacements = mapDefined(exportDecl.exportClause!.elements, e => { + if (!e.propertyName) { + // export {name} - look thru `statements` for `name`, and if all results can take an `export` modifier, do so and filter it + const associated = filter(statements, s => nodeHasName(s, e.name)); + if (length(associated) && every(associated, canHaveExportModifier)) { + forEach(associated, addExportModifier); + return undefined; + } + } + return e; + }); + if (!length(replacements)) { + // all clauses removed, filter the export declaration + statements = filter(statements, s => s !== exportDecl); + } + else { + // some items filtered, others not - update the export declaration + // (mutating because why not, we're building a whole new tree here anyway) + exportDecl.exportClause!.elements = createNodeArray(replacements); + } + } + return statements; + } + + function mergeRedundantStatements(statements: Statement[]) { + statements = flattenExportAssignedNamespace(statements); + statements = mergeExportDeclarations(statements); + statements = inlineExportModifiers(statements); + + // Not a cleanup, but as a final step: If there is a mix of `export` and non-`export` declarations, but no `export =` or `export {}` add a `export {};` so + // declaration privacy is respected. + if (enclosingDeclaration && + ((isSourceFile(enclosingDeclaration) && isExternalOrCommonJsModule(enclosingDeclaration)) || isModuleDeclaration(enclosingDeclaration)) && + (!some(statements, isExternalModuleIndicator) || (!hasScopeMarker(statements) && some(statements, needsScopeMarker)))) { + statements.push(createEmptyExports()); + } + return statements; + } + + function canHaveExportModifier(node: Statement) { + return isEnumDeclaration(node) || + isVariableStatement(node) || + isFunctionDeclaration(node) || + isClassDeclaration(node) || + (isModuleDeclaration(node) && !isExternalModuleAugmentation(node) && !isGlobalScopeAugmentation(node)) || + isInterfaceDeclaration(node) || + isTypeDeclaration(node); + } + + function addExportModifier(statement: Statement) { + const flags = (getModifierFlags(statement) | ModifierFlags.Export) & ~ModifierFlags.Ambient; + statement.modifiers = createNodeArray(createModifiersFromModifierFlags(flags)); + statement.modifierFlagsCache = 0; + } + + function visitSymbolTable(symbolTable: SymbolTable, suppressNewPrivateContext?: boolean, propertyAsAlias?: boolean) { + const oldDeferredPrivates = deferredPrivates; + if (!suppressNewPrivateContext) { + deferredPrivates = createMap(); + } + symbolTable.forEach((symbol: Symbol) => { + serializeSymbol(symbol, /*isPrivate*/ false, !!propertyAsAlias); + }); + if (!suppressNewPrivateContext) { + // deferredPrivates will be filled up by visiting the symbol table + // And will continue to iterate as elements are added while visited `deferredPrivates` + // (As that's how a map iterator is defined to work) + deferredPrivates!.forEach((symbol: Symbol) => { + serializeSymbol(symbol, /*isPrivate*/ true, !!propertyAsAlias); + }); + } + deferredPrivates = oldDeferredPrivates; + } + + function serializeSymbol(symbol: Symbol, isPrivate: boolean, propertyAsAlias: boolean) { + // cache visited list based on merged symbol, since we want to use the unmerged top-level symbol, but + // still skip reserializing it if we encounter the merged product later on + const visitedSym = getMergedSymbol(symbol); + if (visitedSymbols.has("" + getSymbolId(visitedSym))) { + return; // Already printed + } + visitedSymbols.set("" + getSymbolId(visitedSym), true); + // Only actually serialize symbols within the correct enclosing declaration, otherwise do nothing with the out-of-context symbol + const skipMembershipCheck = !isPrivate; // We only call this on exported symbols when we know they're in the correct scope + if (skipMembershipCheck || (!!length(symbol.declarations) && some(symbol.declarations, d => !!findAncestor(d, n => n === enclosingDeclaration)))) { + const oldContext = context; + context = cloneNodeBuilderContext(context); + const result = serializeSymbolWorker(symbol, isPrivate, propertyAsAlias); + context = oldContext; + return result; + } + } + + // Synthesize declarations for a symbol - might be an Interface, a Class, a Namespace, a Type, a Variable (const, let, or var), an Alias + // or a merge of some number of those. + // An interesting challenge is ensuring that when classes merge with namespaces and interfaces, is keeping + // each symbol in only one of the representations + // Also, synthesizing a default export of some kind + // If it's an alias: emit `export default ref` + // If it's a property: emit `export default _default` with a `_default` prop + // If it's a class/interface/function: emit a class/interface/function with a `default` modifier + // These forms can merge, eg (`export default 12; export default interface A {}`) + function serializeSymbolWorker(symbol: Symbol, isPrivate: boolean, propertyAsAlias: boolean) { + const symbolName = unescapeLeadingUnderscores(symbol.escapedName); + const isDefault = symbol.escapedName === InternalSymbolName.Default; + if (isStringANonContextualKeyword(symbolName) && !isDefault) { + // Oh no. We cannot use this symbol's name as it's name... It's likely some jsdoc had an invalid name like `export` or `default` :( + context.encounteredError = true; + // TODO: Issue error via symbol tracker? + return; // If we need to emit a private with a keyword name, we're done for, since something else will try to refer to it by that name + } + const needsPostExportDefault = isDefault && !!( + symbol.flags & SymbolFlags.ExportDoesNotSupportDefaultModifier + || (symbol.flags & SymbolFlags.Function && length(getPropertiesOfType(getTypeOfSymbol(symbol)))) + ) && !(symbol.flags & SymbolFlags.Alias); // An alias symbol should preclude needing to make an alias ourselves + if (needsPostExportDefault) { + isPrivate = true; + } + const modifierFlags = (!isPrivate ? ModifierFlags.Export : 0) | (isDefault && !needsPostExportDefault ? ModifierFlags.Default : 0); + if (symbol.flags & SymbolFlags.Function) { + serializeAsFunctionNamespaceMerge(getTypeOfSymbol(symbol), symbol, getInternalSymbolName(symbol, symbolName), modifierFlags); + } + if (symbol.flags & SymbolFlags.TypeAlias) { + serializeTypeAlias(symbol, symbolName, modifierFlags); + } + // Need to skip over export= symbols below - json source files get a single `Property` flagged + // symbol of name `export=` which needs to be handled like an alias. It's not great, but it is what it is. + if (symbol.flags & (SymbolFlags.BlockScopedVariable | SymbolFlags.FunctionScopedVariable | SymbolFlags.Property) + && symbol.escapedName !== InternalSymbolName.ExportEquals + && !(symbol.flags & SymbolFlags.Prototype) + && !(symbol.flags & SymbolFlags.Class)) { + serializeVariableOrProperty(symbol, symbolName, isPrivate, needsPostExportDefault, propertyAsAlias, modifierFlags); + } + if (symbol.flags & SymbolFlags.Enum) { + serializeEnum(symbol, symbolName, modifierFlags); + } + if (symbol.flags & SymbolFlags.Class) { + if (symbol.flags & SymbolFlags.Property) { + // Looks like a `module.exports.Sub = class {}` - if we serialize `symbol` as a class, the result will have no members, + // since the classiness is actually from the target of the effective alias the symbol is. yes. A BlockScopedVariable|Class|Property + // _really_ acts like an Alias, and none of a BlockScopedVariable, Class, or Property. This is the travesty of JS binding today. + serializeAsAlias(symbol, getInternalSymbolName(symbol, symbolName), modifierFlags); + } + else { + serializeAsClass(symbol, getInternalSymbolName(symbol, symbolName), modifierFlags); + } + } + if (symbol.flags & (SymbolFlags.ValueModule | SymbolFlags.NamespaceModule)) { + serializeModule(symbol, symbolName, modifierFlags); + } + if (symbol.flags & SymbolFlags.Interface) { + serializeInterface(symbol, symbolName, modifierFlags); + } + if (symbol.flags & SymbolFlags.Alias) { + serializeAsAlias(symbol, getInternalSymbolName(symbol, symbolName), modifierFlags); + } + if (symbol.flags & SymbolFlags.Property && symbol.escapedName === InternalSymbolName.ExportEquals) { + serializeMaybeAliasAssignment(symbol); + } + if (symbol.flags & SymbolFlags.ExportStar) { + // synthesize export * from "moduleReference" + // Straightforward - only one thing to do - make an export declaration + for (const node of symbol.declarations) { + const resolvedModule = resolveExternalModuleName(node, (node as ExportDeclaration).moduleSpecifier!); + if (!resolvedModule) continue; + addResult(createExportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, /*exportClause*/ undefined, createLiteral(getSpecifierForModuleSymbol(resolvedModule, context))), ModifierFlags.None); + } + } + if (needsPostExportDefault) { + addResult(createExportAssignment(/*decorators*/ undefined, /*modifiers*/ undefined, /*isExportAssignment*/ false, createIdentifier(getInternalSymbolName(symbol, symbolName))), ModifierFlags.None); + } + } + + function includePrivateSymbol(symbol: Symbol) { + Debug.assertDefined(deferredPrivates); + deferredPrivates!.set("" + getSymbolId(symbol), symbol); + } + + function isExportingScope(enclosingDeclaration: Node) { + return ((isSourceFile(enclosingDeclaration) && (isExternalOrCommonJsModule(enclosingDeclaration) || isJsonSourceFile(enclosingDeclaration))) || + (isAmbientModule(enclosingDeclaration) && !isGlobalScopeAugmentation(enclosingDeclaration))); + } + + // Prepends a `declare` and/or `export` modifier if the context requires it, and then adds `node` to `result` and returns `node` + // Note: This _mutates_ `node` without using `updateNode` - the assumption being that all nodes should be manufactured fresh by the node builder + function addResult(node: Statement, additionalModifierFlags: ModifierFlags) { + let newModifierFlags: ModifierFlags = ModifierFlags.None; + if (additionalModifierFlags & ModifierFlags.Export && + enclosingDeclaration && + isExportingScope(enclosingDeclaration) && + canHaveExportModifier(node) + ) { + // Classes, namespaces, variables, functions, interfaces, and types should all be `export`ed in a module context if not private + newModifierFlags |= ModifierFlags.Export; + } + if (addingDeclare && !(newModifierFlags & ModifierFlags.Export) && + (!enclosingDeclaration || !(enclosingDeclaration.flags & NodeFlags.Ambient)) && + (isEnumDeclaration(node) || isVariableStatement(node) || isFunctionDeclaration(node) || isClassDeclaration(node) || isModuleDeclaration(node))) { + // Classes, namespaces, variables, enums, and functions all need `declare` modifiers to be valid in a declaration file top-level scope + newModifierFlags |= ModifierFlags.Ambient; + } + if ((additionalModifierFlags & ModifierFlags.Default) && (isClassDeclaration(node) || isInterfaceDeclaration(node) || isFunctionDeclaration(node))) { + newModifierFlags |= ModifierFlags.Default; + } + if (newModifierFlags) { + node.modifiers = createNodeArray(createModifiersFromModifierFlags(newModifierFlags | getModifierFlags(node))); + node.modifierFlagsCache = 0; // Reset computed flags cache + } + results.push(node); + } + + function serializeTypeAlias(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) { + const aliasType = getDeclaredTypeOfTypeAlias(symbol); + const typeParams = getSymbolLinks(symbol).typeParameters; + const typeParamDecls = map(typeParams, p => typeParameterToDeclaration(p, context)); + const jsdocAliasDecl = find(symbol.declarations, isJSDocTypeAlias); + const commentText = jsdocAliasDecl ? jsdocAliasDecl.comment || jsdocAliasDecl.parent.comment : undefined; + const oldFlags = context.flags; + context.flags |= NodeBuilderFlags.InTypeAlias; + addResult(setSyntheticLeadingComments( + createTypeAliasDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, getInternalSymbolName(symbol, symbolName), typeParamDecls, typeToTypeNodeHelper(aliasType, context)), + !commentText ? [] : [{ kind: SyntaxKind.MultiLineCommentTrivia, text: "*\n * " + commentText.replace(/\n/g, "\n * ") + "\n ", pos: -1, end: -1, hasTrailingNewLine: true }] + ), modifierFlags); + context.flags = oldFlags; + } + + function serializeInterface(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) { + const interfaceType = getDeclaredTypeOfClassOrInterface(symbol); + const localParams = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); + const typeParamDecls = map(localParams, p => typeParameterToDeclaration(p, context)); + const baseTypes = getBaseTypes(interfaceType); + const baseType = length(baseTypes) ? getIntersectionType(baseTypes) : undefined; + const members = flatMap(getPropertiesOfType(interfaceType), p => serializePropertySymbolForInterface(p, baseType)); + const callSignatures = serializeSignatures(SignatureKind.Call, interfaceType, baseType, SyntaxKind.CallSignature) as CallSignatureDeclaration[]; + const constructSignatures = serializeSignatures(SignatureKind.Construct, interfaceType, baseType, SyntaxKind.ConstructSignature) as ConstructSignatureDeclaration[]; + const indexSignatures = serializeIndexSignatures(interfaceType, baseType); + + const heritageClauses = !length(baseTypes) ? undefined : [createHeritageClause(SyntaxKind.ExtendsKeyword, mapDefined(baseTypes, b => trySerializeAsTypeReference(b)))]; + addResult(createInterfaceDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + getInternalSymbolName(symbol, symbolName), + typeParamDecls, + heritageClauses, + [...indexSignatures, ...constructSignatures, ...callSignatures, ...members] + ), modifierFlags); + } + + function serializeModule(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) { + const members = !symbol.exports ? [] : filter(arrayFrom((symbol.exports).values()), p => !((p.flags & SymbolFlags.Prototype) || (p.escapedName === "prototype"))); + // Split NS members up by declaration - members whose parent symbol is the ns symbol vs those whose is not (but were added in later via merging) + const locationMap = arrayToMultiMap(members, m => m.parent && m.parent === symbol ? "real" : "merged"); + const realMembers = locationMap.get("real") || emptyArray; + const mergedMembers = locationMap.get("merged") || emptyArray; + // TODO: `suppressNewPrivateContext` is questionable -we need to simply be emitting privates in whatever scope they were declared in, rather + // than whatever scope we traverse to them in. That's a bit of a complex rewrite, since we're not _actually_ tracking privates at all in advance, + // so we don't even have placeholders to fill in. + if (length(realMembers)) { + const localName = getInternalSymbolName(symbol, symbolName); + serializeAsNamespaceDeclaration(realMembers, localName, modifierFlags, /*suppressNewPrivateContext*/ false); + } + if (length(mergedMembers)) { + const localName = getInternalSymbolName(symbol, symbolName); + forEach(mergedMembers, includePrivateSymbol); + const nsBody = createModuleBlock([createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamedExports(map(filter(mergedMembers, n => n.escapedName !== InternalSymbolName.ExportEquals), s => { + const name = unescapeLeadingUnderscores(s.escapedName); + const localName = getInternalSymbolName(s, name); + return createExportSpecifier(name === localName ? undefined : localName, name); + })) + )]); + addResult(createModuleDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createIdentifier(localName), + nsBody, + NodeFlags.Namespace + ), ModifierFlags.None); + } + } + + function serializeEnum(symbol: Symbol, symbolName: string, modifierFlags: ModifierFlags) { + addResult(createEnumDeclaration( + /*decorators*/ undefined, + createModifiersFromModifierFlags(isConstEnumSymbol(symbol) ? ModifierFlags.Const : 0), + getInternalSymbolName(symbol, symbolName), + map(filter(getPropertiesOfType(getTypeOfSymbol(symbol)), p => !!(p.flags & SymbolFlags.EnumMember)), p => { + // TODO: Handle computed names + // I hate that to get the initialized value we need to walk back to the declarations here; but there's no + // other way to get the possible const value of an enum member that I'm aware of, as the value is cached + // _on the declaration_, not on the declaration's symbol... + const initializedValue = p.declarations && p.declarations[0] && isEnumMember(p.declarations[0]) && getConstantValue(p.declarations[0] as EnumMember); + return createEnumMember(unescapeLeadingUnderscores(p.escapedName), initializedValue === undefined ? undefined : createLiteral(initializedValue)); + }) + ), modifierFlags); + } + + function serializeVariableOrProperty(symbol: Symbol, symbolName: string, isPrivate: boolean, needsPostExportDefault: boolean, propertyAsAlias: boolean | undefined, modifierFlags: ModifierFlags) { + if (propertyAsAlias) { + serializeMaybeAliasAssignment(symbol); + } + else { + const type = getTypeOfSymbol(symbol); + const localName = getInternalSymbolName(symbol, symbolName); + if (!(symbol.flags & SymbolFlags.Function) && isTypeRepresentableAsFunctionNamespaceMerge(type, symbol)) { + // If the type looks like a function declaration + ns could represent it, and it's type is sourced locally, rewrite it into a function declaration + ns + serializeAsFunctionNamespaceMerge(type, symbol, localName, modifierFlags); + } + else { + // A Class + Property merge is made for a `module.exports.Member = class {}`, and it doesn't serialize well as either a class _or_ a property symbol - in fact, _it behaves like an alias!_ + // `var` is `FunctionScopedVariable`, `const` and `let` are `BlockScopedVariable`, and `module.exports.thing =` is `Property` + const flags = !(symbol.flags & SymbolFlags.BlockScopedVariable) ? undefined + : isConstVariable(symbol) ? NodeFlags.Const + : NodeFlags.Let; + const name = (needsPostExportDefault || !(symbol.flags & SymbolFlags.Property)) ? localName : getUnusedName(localName, symbol); + let textRange: Node | undefined = symbol.declarations && find(symbol.declarations, d => isVariableDeclaration(d)); + if (textRange && isVariableDeclarationList(textRange.parent) && textRange.parent.declarations.length === 1) { + textRange = textRange.parent.parent; + } + const statement = setTextRange(createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([ + createVariableDeclaration(name, serializeTypeForDeclaration(type, symbol)) + ], flags)), textRange); + addResult(statement, name !== localName ? modifierFlags & ~ModifierFlags.Export : modifierFlags); + if (name !== localName && !isPrivate) { + // We rename the variable declaration we generate for Property symbols since they may have a name which + // conflicts with a local declaration. For example, given input: + // ``` + // function g() {} + // module.exports.g = g + // ``` + // In such a situation, we have a local variable named `g`, and a seperate exported variable named `g`. + // Naively, we would emit + // ``` + // function g() {} + // export const g: typeof g; + // ``` + // That's obviously incorrect - the `g` in the type annotation needs to refer to the local `g`, but + // the export declaration shadows it. + // To work around that, we instead write + // ``` + // function g() {} + // const g_1: typeof g; + // export { g_1 as g }; + // ``` + // To create an export named `g` that does _not_ shadow the local `g` + addResult( + createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamedExports([createExportSpecifier(name, localName)]) + ), + ModifierFlags.None + ); + } + } + } + } + + function serializeAsFunctionNamespaceMerge(type: Type, symbol: Symbol, localName: string, modifierFlags: ModifierFlags) { + const signatures = getSignaturesOfType(type, SignatureKind.Call); + for (const sig of signatures) { + // Each overload becomes a separate function declaration, in order + const decl = signatureToSignatureDeclarationHelper(sig, SyntaxKind.FunctionDeclaration, context) as FunctionDeclaration; + decl.name = createIdentifier(localName); + addResult(setTextRange(decl, sig.declaration), modifierFlags); + } + // Module symbol emit will take care of module-y members, provided it has exports + if (!(symbol.flags & (SymbolFlags.ValueModule | SymbolFlags.NamespaceModule) && !!symbol.exports && !!symbol.exports.size)) { + const props = filter(getPropertiesOfType(type), p => !((p.flags & SymbolFlags.Prototype) || (p.escapedName === "prototype"))); + serializeAsNamespaceDeclaration(props, localName, modifierFlags, /*suppressNewPrivateContext*/ true); + } + } + + function serializeAsNamespaceDeclaration(props: readonly Symbol[], localName: string, modifierFlags: ModifierFlags, suppressNewPrivateContext: boolean) { + if (length(props)) { + const localVsRemoteMap = arrayToMultiMap(props, p => + !length(p.declarations) || some(p.declarations, d => + getSourceFileOfNode(d) === getSourceFileOfNode(context.enclosingDeclaration!) + ) ? "local" : "remote" + ); + const localProps = localVsRemoteMap.get("local") || emptyArray; + // handle remote props first - we need to make an `import` declaration that points at the module containing each remote + // prop in the outermost scope (TODO: a namespace within a namespace would need to be appropriately handled by this) + // Example: + // import Foo_1 = require("./exporter"); + // export namespace ns { + // import Foo = Foo_1.Foo; + // export { Foo }; + // export const c: number; + // } + // This is needed because in JS, statements like `const x = require("./f")` support both type and value lookup, even if they're + // normally just value lookup (so it functions kinda like an alias even when it's not an alias) + // _Usually_, we'll simply print the top-level as an alias instead of a `var` in such situations, however is is theoretically + // possible to encounter a situation where a type has members from both the current file and other files - in those situations, + // emit akin to the above would be needed. + + // Add a namespace + const fakespace = createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createIdentifier(localName), createModuleBlock([]), NodeFlags.Namespace); + fakespace.flags ^= NodeFlags.Synthesized; // unset synthesized so it is usable as an enclosing declaration + fakespace.parent = enclosingDeclaration as SourceFile | NamespaceDeclaration; + fakespace.locals = createSymbolTable(props); + fakespace.symbol = props[0].parent!; + const oldResults = results; + results = []; + const oldAddingDeclare = addingDeclare; + addingDeclare = false; + const subcontext = { ...context, enclosingDeclaration: fakespace }; + const oldContext = context; + context = subcontext; + // TODO: implement handling for the localVsRemoteMap.get("remote") - should be difficult to trigger (see comment above), as only interesting cross-file js merges should make this possible + visitSymbolTable(createSymbolTable(localProps), suppressNewPrivateContext, /*propertyAsAlias*/ true); + context = oldContext; + addingDeclare = oldAddingDeclare; + const declarations = results; + results = oldResults; + fakespace.flags ^= NodeFlags.Synthesized; // reset synthesized + fakespace.parent = undefined!; + fakespace.locals = undefined!; + fakespace.symbol = undefined!; + fakespace.body = createModuleBlock(declarations); + addResult(fakespace, modifierFlags); // namespaces can never be default exported + } + } + + function serializeAsClass(symbol: Symbol, localName: string, modifierFlags: ModifierFlags) { + const localParams = getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol); + const typeParamDecls = map(localParams, p => typeParameterToDeclaration(p, context)); + const classType = getDeclaredTypeOfClassOrInterface(symbol); + const baseTypes = getBaseTypes(classType); + const staticType = getTypeOfSymbol(symbol); + const staticBaseType = getBaseConstructorTypeOfClass(staticType as InterfaceType); + const heritageClauses = !length(baseTypes) ? undefined : [createHeritageClause(SyntaxKind.ExtendsKeyword, map(baseTypes, b => serializeBaseType(b, staticBaseType, localName)))]; + const members = flatMap(getPropertiesOfType(classType), p => serializePropertySymbolForClass(p, /*isStatic*/ false, baseTypes[0])); + // Consider static members empty if symbol also has function or module meaning - function namespacey emit will handle statics + const staticMembers = symbol.flags & (SymbolFlags.Function | SymbolFlags.ValueModule) + ? [] + : flatMap(filter( + getPropertiesOfType(staticType), + p => !(p.flags & SymbolFlags.Prototype) && p.escapedName !== "prototype" + ), p => serializePropertySymbolForClass(p, /*isStatic*/ true, staticBaseType)); + const constructors = serializeSignatures(SignatureKind.Construct, staticType, baseTypes[0], SyntaxKind.Constructor) as ConstructorDeclaration[]; + for (const c of constructors) { + // A constructor's return type and type parameters are supposed to be controlled by the enclosing class declaration + // `signatureToSignatureDeclarationHelper` appends them regardless, so for now we delete them here + c.type = undefined; + c.typeParameters = undefined; + } + const indexSignatures = serializeIndexSignatures(classType, baseTypes[0]); + addResult(setTextRange(createClassDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + localName, + typeParamDecls, + heritageClauses, + [...indexSignatures, ...staticMembers, ...constructors, ...members] + ), symbol.declarations && filter(symbol.declarations, d => isClassDeclaration(d) || isClassExpression(d))[0]), modifierFlags); + } + + function serializeAsAlias(symbol: Symbol, localName: string, modifierFlags: ModifierFlags) { + // synthesize an alias, eg `export { symbolName as Name }` + // need to mark the alias `symbol` points + // at as something we need to serialize as a private declaration as well + const node = getDeclarationOfAliasSymbol(symbol); + if (!node) return Debug.fail(); + const target = getMergedSymbol(getTargetOfAliasDeclaration(node, /*dontRecursivelyResolve*/ true)); + if (!target) { + return; + } + let verbatimTargetName = unescapeLeadingUnderscores(target.escapedName); + if (verbatimTargetName === InternalSymbolName.ExportEquals && (compilerOptions.esModuleInterop || compilerOptions.allowSyntheticDefaultImports)) { + // target refers to an `export=` symbol that was hoisted into a synthetic default - rename here to match + verbatimTargetName = InternalSymbolName.Default; + } + const targetName = getInternalSymbolName(target, verbatimTargetName); + includePrivateSymbol(target); // the target may be within the same scope - attempt to serialize it first + switch (node.kind) { + case SyntaxKind.ImportEqualsDeclaration: + // Could be a local `import localName = ns.member` or + // an external `import localName = require("whatever")` + const isLocalImport = !(target.flags & SymbolFlags.ValueModule); + addResult(createImportEqualsDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createIdentifier(localName), + isLocalImport + ? symbolToName(target, context, SymbolFlags.All, /*expectsIdentifier*/ false) + : createExternalModuleReference(createLiteral(getSpecifierForModuleSymbol(symbol, context))) + ), isLocalImport ? modifierFlags : ModifierFlags.None); + break; + case SyntaxKind.NamespaceExportDeclaration: + // export as namespace foo + // TODO: Not part of a file's local or export symbol tables + // Is bound into file.symbol.globalExports instead, which we don't currently traverse + addResult(createNamespaceExportDeclaration(idText((node as NamespaceExportDeclaration).name)), ModifierFlags.None); + break; + case SyntaxKind.ImportClause: + addResult(createImportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createImportClause(createIdentifier(localName), /*namedBindings*/ undefined), + createLiteral(getSpecifierForModuleSymbol(target.parent!, context)) + ), ModifierFlags.None); + break; + case SyntaxKind.NamespaceImport: + addResult(createImportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createImportClause(/*importClause*/ undefined, createNamespaceImport(createIdentifier(localName))), + createLiteral(getSpecifierForModuleSymbol(target, context)) + ), ModifierFlags.None); + break; + case SyntaxKind.ImportSpecifier: + addResult(createImportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createImportClause(/*importClause*/ undefined, createNamedImports([ + createImportSpecifier( + localName !== verbatimTargetName ? createIdentifier(verbatimTargetName) : undefined, + createIdentifier(localName) + ) + ])), + createLiteral(getSpecifierForModuleSymbol(target.parent!, context)) + ), ModifierFlags.None); + break; + case SyntaxKind.ExportSpecifier: + // does not use localName because the symbol name in this case refers to the name in the exports table, + // which we must exactly preserve + const specifier = (node.parent.parent as ExportDeclaration).moduleSpecifier; + // targetName is only used when the target is local, as otherwise the target is an alias that points at + // another file + serializeExportSpecifier( + unescapeLeadingUnderscores(symbol.escapedName), + specifier ? verbatimTargetName : targetName, + specifier && isStringLiteralLike(specifier) ? createLiteral(specifier.text) : undefined + ); + break; + case SyntaxKind.ExportAssignment: + serializeMaybeAliasAssignment(symbol); + break; + case SyntaxKind.BinaryExpression: + // Could be best encoded as though an export specifier or as though an export assignment + // If name is default or export=, do an export assignment + // Otherwise do an export specifier + if (symbol.escapedName === InternalSymbolName.Default || symbol.escapedName === InternalSymbolName.ExportEquals) { + serializeMaybeAliasAssignment(symbol); + } + else { + serializeExportSpecifier(localName, targetName); + } + break; + case SyntaxKind.PropertyAccessExpression: + // A PAE alias is _always_ going to exist as an append to a top-level export, where our top level + // handling should always be sufficient to encode the export action itself + break; + default: + return Debug.failBadSyntaxKind(node, "Unhandled alias declaration kind in symbol serializer!"); + } + } + + function serializeExportSpecifier(localName: string, targetName: string, specifier?: Expression) { + addResult(createExportDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createNamedExports([createExportSpecifier(localName !== targetName ? targetName : undefined, localName)]), + specifier + ), ModifierFlags.None); + } + + function serializeMaybeAliasAssignment(symbol: Symbol) { + if (symbol.flags & SymbolFlags.Prototype) { + return; + } + const name = unescapeLeadingUnderscores(symbol.escapedName); + const isExportEquals = name === InternalSymbolName.ExportEquals; + const isDefault = name === InternalSymbolName.Default; + const isExportAssignment = isExportEquals || isDefault; + // synthesize export = ref + // ref should refer to either be a locally scoped symbol which we need to emit, or + // a reference to another namespace/module which we may need to emit an `import` statement for + const aliasDecl = symbol.declarations && getDeclarationOfAliasSymbol(symbol); + // serialize what the alias points to, preserve the declaration's initializer + const target = aliasDecl && getTargetOfAliasDeclaration(aliasDecl, /*dontRecursivelyResolve*/ true); + if (target) { + // In case `target` refers to a namespace member, look at the declaration and serialize the leftmost symbol in it + // eg, `namespace A { export class B {} }; exports = A.B;` + // Technically, this is all that's required in the case where the assignment is an entity name expression + const expr = isExportAssignment ? getExportAssignmentExpression(aliasDecl as ExportAssignment | BinaryExpression) : getPropertyAssignmentAliasLikeExpression(aliasDecl as ShorthandPropertyAssignment | PropertyAssignment | PropertyAccessExpression); + const first = isEntityNameExpression(expr) ? getFirstNonModuleExportsIdentifier(expr) : undefined; + const referenced = first && resolveEntityName(first, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveAlias*/ true, enclosingDeclaration); + if (referenced || target) { + includePrivateSymbol(referenced || target); + } + + // We disable the context's symbol traker for the duration of this name serialization + // as, by virtue of being here, the name is required to print something, and we don't want to + // issue a visibility error on it. Only anonymous classes that an alias points at _would_ issue + // a visibility error here (as they're not visible within any scope), but we want to hoist them + // into the containing scope anyway, so we want to skip the visibility checks. + const oldTrack = context.tracker.trackSymbol; + context.tracker.trackSymbol = noop; + if (isExportAssignment) { + results.push(createExportAssignment( + /*decorators*/ undefined, + /*modifiers*/ undefined, + isExportEquals, + symbolToExpression(target, context, SymbolFlags.All) + )); + } + else { + if (first === expr) { + // serialize as `export {target as name}` + serializeExportSpecifier(name, idText(first)); + } + else if (isClassExpression(expr)) { + serializeExportSpecifier(name, getInternalSymbolName(target, symbolName(target))); + } + else { + // serialize as `import _Ref = t.arg.et; export { _Ref as name }` + const varName = getUnusedName(name, symbol); + addResult(createImportEqualsDeclaration( + /*decorators*/ undefined, + /*modifiers*/ undefined, + createIdentifier(varName), + symbolToName(target, context, SymbolFlags.All, /*expectsIdentifier*/ false) + ), ModifierFlags.None); + serializeExportSpecifier(name, varName); + } + } + context.tracker.trackSymbol = oldTrack; + } + else { + // serialize as an anonymous property declaration + const varName = getUnusedName(name, symbol); + // We have to use `getWidenedType` here since the object within a json file is unwidened within the file + // (Unwidened types can only exist in expression contexts and should never be serialized) + const typeToSerialize = getWidenedType(getTypeOfSymbol(symbol)); + if (isTypeRepresentableAsFunctionNamespaceMerge(typeToSerialize, symbol)) { + // If there are no index signatures and `typeToSerialize` is an object type, emit as a namespace instead of a const + serializeAsFunctionNamespaceMerge(typeToSerialize, symbol, varName, isExportAssignment ? ModifierFlags.None : ModifierFlags.Export); + } + else { + const statement = createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([ + createVariableDeclaration(varName, serializeTypeForDeclaration(typeToSerialize, symbol)) + ], NodeFlags.Const)); + addResult(statement, name === varName ? ModifierFlags.Export : ModifierFlags.None); + } + if (isExportAssignment) { + results.push(createExportAssignment( + /*decorators*/ undefined, + /*modifiers*/ undefined, + isExportEquals, + createIdentifier(varName) + )); + } + else if (name !== varName) { + serializeExportSpecifier(name, varName); + } + } + } + + function isTypeRepresentableAsFunctionNamespaceMerge(typeToSerialize: Type, hostSymbol: Symbol) { + // Only object types which are not constructable, or indexable, whose members all come from the + // context source file, and whose property names are all valid identifiers and not late-bound, _and_ + // whose input is not type annotated (if the input symbol has an annotation we can reuse, we should prefer it) + const ctxSrc = getSourceFileOfNode(context.enclosingDeclaration); + return getObjectFlags(typeToSerialize) & (ObjectFlags.Anonymous | ObjectFlags.Mapped) && + !getIndexInfoOfType(typeToSerialize, IndexKind.String) && + !getIndexInfoOfType(typeToSerialize, IndexKind.Number) && + !length(getSignaturesOfType(typeToSerialize, SignatureKind.Construct)) && // TODO: could probably serialize as function + ns + class, now that that's OK + !getDeclarationWithTypeAnnotation(hostSymbol) && + !(typeToSerialize.symbol && some(typeToSerialize.symbol.declarations, d => getSourceFileOfNode(d) !== ctxSrc)) && + !some(getPropertiesOfType(typeToSerialize), p => isLateBoundName(p.escapedName)) && + !some(getPropertiesOfType(typeToSerialize), p => some(p.declarations, d => getSourceFileOfNode(d) !== ctxSrc)) && + every(getPropertiesOfType(typeToSerialize), p => isIdentifierText(symbolName(p), languageVersion) && !isStringAKeyword(symbolName(p))); + } + + function makeSerializePropertySymbol(createProperty: ( + decorators: readonly Decorator[] | undefined, + modifiers: readonly Modifier[] | undefined, + name: string | PropertyName, + questionOrExclamationToken: QuestionToken | undefined, + type: TypeNode | undefined, + initializer: Expression | undefined + ) => T, methodKind: SyntaxKind): (p: Symbol, isStatic: boolean, baseType: Type | undefined) => (T | T[]) { + return function serializePropertySymbol(p: Symbol, isStatic: boolean, baseType: Type | undefined) { + if (isStatic && (p.flags & (SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias))) { + // Only value-only-meaning symbols can be correctly encoded as class statics, type/namespace/alias meaning symbols + // need to be merged namespace members + return []; + } + if (p.flags & SymbolFlags.Prototype || (baseType && getPropertyOfType(baseType, p.escapedName) + && isReadonlySymbol(getPropertyOfType(baseType, p.escapedName)!) === isReadonlySymbol(p) + && (p.flags & SymbolFlags.Optional) === (getPropertyOfType(baseType, p.escapedName)!.flags & SymbolFlags.Optional) + && isTypeIdenticalTo(getTypeOfSymbol(p), getTypeOfPropertyOfType(baseType, p.escapedName)!))) { + return []; + } + const staticFlag = isStatic ? ModifierFlags.Static : 0; + const rawName = unescapeLeadingUnderscores(p.escapedName); + const name = getPropertyNameNodeForSymbolFromNameType(p, context) || createIdentifier(rawName); + if (p.flags & (SymbolFlags.Property | SymbolFlags.Accessor | SymbolFlags.Variable)) { + return setTextRange(createProperty( + /*decorators*/ undefined, + createModifiersFromModifierFlags((isReadonlySymbol(p) ? ModifierFlags.Readonly : 0) | staticFlag), + name, + p.flags & SymbolFlags.Optional ? createToken(SyntaxKind.QuestionToken) : undefined, + serializeTypeForDeclaration(getTypeOfSymbol(p), p), + // TODO: https://github.com/microsoft/TypeScript/pull/32372#discussion_r328386357 + // interface members can't have initializers, however class members _can_ + /*initializer*/ undefined + ), filter(p.declarations, d => isPropertyDeclaration(d) || isAccessor(d) || isVariableDeclaration(d) || isPropertySignature(d) || isBinaryExpression(d) || isPropertyAccessExpression(d))[0]); + } + if (p.flags & (SymbolFlags.Method | SymbolFlags.Function)) { + const type = getTypeOfSymbol(p); + const signatures = getSignaturesOfType(type, SignatureKind.Call); + const results = []; + for (const sig of signatures) { + // Each overload becomes a separate method declaration, in order + const decl = signatureToSignatureDeclarationHelper(sig, methodKind, context) as MethodDeclaration; + decl.name = name; // TODO: Clone + if (staticFlag) { + decl.modifiers = createNodeArray(createModifiersFromModifierFlags(staticFlag)); + } + if (p.flags & SymbolFlags.Optional) { + decl.questionToken = createToken(SyntaxKind.QuestionToken); + } + results.push(setTextRange(decl, sig.declaration)); + } + return results as unknown as T[]; + } + // The `Constructor`'s symbol isn't in the class's properties lists, obviously, since it's a signature on the static + return Debug.fail(`Unhandled class member kind! ${(p as any).__debugFlags || p.flags}`); + }; + } + + function serializePropertySymbolForInterface(p: Symbol, baseType: Type | undefined) { + return serializePropertySymbolForInterfaceWorker(p, /*isStatic*/ false, baseType); + } + + function getDeclarationWithTypeAnnotation(symbol: Symbol) { + return find(symbol.declarations, s => !!getEffectiveTypeAnnotationNode(s) && !!findAncestor(s, n => n === enclosingDeclaration)); + } + + /** + * Unlike `typeToTypeNodeHelper`, this handles setting up the `AllowUniqueESSymbolType` flag + * so a `unique symbol` is returned when appropriate for the input symbol, rather than `typeof sym` + */ + function serializeTypeForDeclaration(type: Type, symbol: Symbol) { + const declWithExistingAnnotation = getDeclarationWithTypeAnnotation(symbol); + if (declWithExistingAnnotation && !isFunctionLikeDeclaration(declWithExistingAnnotation)) { + // try to reuse the existing annotation + const existing = getEffectiveTypeAnnotationNode(declWithExistingAnnotation)!; + const transformed = visitNode(existing, visitExistingNodeTreeSymbols); + return transformed === existing ? getMutableClone(existing) : transformed; + } + const oldFlags = context.flags; + if (type.flags & TypeFlags.UniqueESSymbol && + type.symbol === symbol) { + context.flags |= NodeBuilderFlags.AllowUniqueESSymbolType; + } + const result = typeToTypeNodeHelper(type, context); + context.flags = oldFlags; + return result; + + function visitExistingNodeTreeSymbols(node: T): Node { + if (isJSDocAllType(node)) { + return createKeywordTypeNode(SyntaxKind.AnyKeyword); + } + if (isJSDocUnknownType(node)) { + return createKeywordTypeNode(SyntaxKind.UnknownKeyword); + } + if (isJSDocNullableType(node)) { + return createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols), createKeywordTypeNode(SyntaxKind.NullKeyword)]); + } + if (isJSDocOptionalType(node)) { + return createUnionTypeNode([visitNode(node.type, visitExistingNodeTreeSymbols), createKeywordTypeNode(SyntaxKind.UndefinedKeyword)]); + } + if (isJSDocNonNullableType(node)) { + return visitNode(node.type, visitExistingNodeTreeSymbols); + } + if ((isExpressionWithTypeArguments(node) || isTypeReferenceNode(node)) && isJSDocIndexSignature(node)) { + return createTypeLiteralNode([createIndexSignature( + /*decorators*/ undefined, + /*modifiers*/ undefined, + [createParameter( + /*decorators*/ undefined, + /*modifiers*/ undefined, + /*dotdotdotToken*/ undefined, + "x", + /*questionToken*/ undefined, + visitNode(node.typeArguments![0], visitExistingNodeTreeSymbols) + )], + visitNode(node.typeArguments![1], visitExistingNodeTreeSymbols) + )]); + } + if (isJSDocFunctionType(node)) { + if (isJSDocConstructSignature(node)) { + let newTypeNode: TypeNode | undefined; + return createConstructorTypeNode( + visitNodes(node.typeParameters, visitExistingNodeTreeSymbols), + mapDefined(node.parameters, (p, i) => p.name && isIdentifier(p.name) && p.name.escapedText === "new" ? (newTypeNode = p.type, undefined) : createParameter( + /*decorators*/ undefined, + /*modifiers*/ undefined, + p.dotDotDotToken, + p.name || p.dotDotDotToken ? `args` : `arg${i}`, + p.questionToken, + visitNode(p.type, visitExistingNodeTreeSymbols), + /*initializer*/ undefined + )), + visitNode(newTypeNode || node.type, visitExistingNodeTreeSymbols) + ); + } + else { + return createFunctionTypeNode( + visitNodes(node.typeParameters, visitExistingNodeTreeSymbols), + map(node.parameters, (p, i) => createParameter( + /*decorators*/ undefined, + /*modifiers*/ undefined, + p.dotDotDotToken, + p.name || p.dotDotDotToken ? `args` : `arg${i}`, + p.questionToken, + visitNode(p.type, visitExistingNodeTreeSymbols), + /*initializer*/ undefined + )), + visitNode(node.type, visitExistingNodeTreeSymbols) + ); + } + } + if (isLiteralImportTypeNode(node)) { + return updateImportTypeNode( + node, + updateLiteralTypeNode(node.argument, rewriteModuleSpecifier(node, node.argument.literal)), + node.qualifier, + visitNodes(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode), + node.isTypeOf + ); + } + + if (isEntityName(node) || isEntityNameExpression(node)) { + const leftmost = getFirstIdentifier(node); + const sym = resolveEntityName(leftmost, SymbolFlags.All, /*ignoreErrors*/ true, /*dontResolveALias*/ true); + if (sym) { + includePrivateSymbol(sym); + if (isIdentifier(node) && sym.flags & SymbolFlags.TypeParameter) { + const name = typeParameterToName(getDeclaredTypeOfSymbol(sym), context); + if (idText(name) !== idText(node)) { + return name; + } + return node; + } + } + } + + return visitEachChild(node, visitExistingNodeTreeSymbols, nullTransformationContext); + } + + function rewriteModuleSpecifier(parent: ImportTypeNode, lit: StringLiteral) { + if (bundled) { + if (context.tracker && context.tracker.moduleResolverHost) { + const targetFile = getExternalModuleFileFromDeclaration(parent); + if (targetFile) { + const getCanonicalFileName = createGetCanonicalFileName(!!host.useCaseSensitiveFileNames); + const resolverHost = { + getCanonicalFileName, + getCurrentDirectory: context.tracker.moduleResolverHost.getCurrentDirectory ? () => context.tracker.moduleResolverHost!.getCurrentDirectory!() : () => "", + getCommonSourceDirectory: () => context.tracker.moduleResolverHost!.getCommonSourceDirectory() + }; + const newName = getResolvedExternalModuleName(resolverHost, targetFile); + return createLiteral(newName); + } + } + } + else { + if (context.tracker && context.tracker.trackExternalModuleSymbolOfImportTypeNode) { + const moduleSym = resolveExternalModuleNameWorker(lit, lit, /*moduleNotFoundError*/ undefined); + if (moduleSym) { + context.tracker.trackExternalModuleSymbolOfImportTypeNode(moduleSym); + } + } + } + return lit; + } + } + + function serializeSignatures(kind: SignatureKind, input: Type, baseType: Type | undefined, outputKind: SyntaxKind) { + const signatures = getSignaturesOfType(input, kind); + if (kind === SignatureKind.Construct) { + if (!baseType && every(signatures, s => length(s.parameters) === 0)) { + return []; // No base type, every constructor is empty - elide the extraneous `constructor()` + } + if (baseType) { + // If there is a base type, if every signature in the class is identical to a signature in the baseType, elide all the declarations + const baseSigs = getSignaturesOfType(baseType, SignatureKind.Construct); + if (!length(baseSigs) && every(signatures, s => length(s.parameters) === 0)) { + return []; // Base had no explicit signatures, if all our signatures are also implicit, return an empty list + } + if (baseSigs.length === signatures.length) { + let failed = false; + for (let i = 0; i < baseSigs.length; i++) { + if (!compareSignaturesIdentical(signatures[i], baseSigs[i], /*partialMatch*/ false, /*ignoreThisTypes*/ false, /*ignoreReturnTypes*/ true, compareTypesIdentical)) { + failed = true; + break; + } + } + if (!failed) { + return []; // Every signature was identical - elide constructor list as it is inherited + } + } + } + } + + const results = []; + for (const sig of signatures) { + // Each overload becomes a separate constructor declaration, in order + const decl = signatureToSignatureDeclarationHelper(sig, outputKind, context); + results.push(setTextRange(decl, sig.declaration)); + } + return results; + } + + function serializeIndexSignatures(input: Type, baseType: Type | undefined) { + const results: IndexSignatureDeclaration[] = []; + for (const type of [IndexKind.String, IndexKind.Number]) { + const info = getIndexInfoOfType(input, type); + if (info) { + if (baseType) { + const baseInfo = getIndexInfoOfType(baseType, type); + if (baseInfo) { + if (isTypeIdenticalTo(info.type, baseInfo.type)) { + continue; // elide identical index signatures + } + } + } + results.push(indexInfoToIndexSignatureDeclarationHelper(info, type, context)); + } + } + return results; + } + + function serializeBaseType(t: Type, staticType: Type, rootName: string) { + const ref = trySerializeAsTypeReference(t); + if (ref) { + return ref; + } + const tempName = getUnusedName(`${rootName}_base`); + const statement = createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([ + createVariableDeclaration(tempName, typeToTypeNodeHelper(staticType, context)) + ], NodeFlags.Const)); + addResult(statement, ModifierFlags.None); + return createExpressionWithTypeArguments(/*typeArgs*/ undefined, createIdentifier(tempName)); + } + + function trySerializeAsTypeReference(t: Type) { + let typeArgs: TypeNode[] | undefined; + let reference: Expression | undefined; + // We don't use `isValueSymbolAccessible` below. since that considers alternative containers (like modules) + // which we can't write out in a syntactically valid way as an expression + if ((t as TypeReference).target && getAccessibleSymbolChain((t as TypeReference).target.symbol, enclosingDeclaration, SymbolFlags.Value, /*useOnlyExternalAliasing*/ false)) { + typeArgs = map(getTypeArguments(t as TypeReference), t => typeToTypeNodeHelper(t, context)); + reference = symbolToExpression((t as TypeReference).target.symbol, context, SymbolFlags.Type); + } + else if (t.symbol && getAccessibleSymbolChain(t.symbol, enclosingDeclaration, SymbolFlags.Value, /*useOnlyExternalAliasing*/ false)) { + reference = symbolToExpression(t.symbol, context, SymbolFlags.Type); + } + if (reference) { + return createExpressionWithTypeArguments(typeArgs, reference); + } + } + + function getUnusedName(input: string, symbol?: Symbol): string { + if (symbol) { + if (context.remappedSymbolNames!.has("" + getSymbolId(symbol))) { + return context.remappedSymbolNames!.get("" + getSymbolId(symbol))!; + } + } + if (input === InternalSymbolName.Default) { + input = "_default"; + } + else if (input === InternalSymbolName.ExportEquals) { + input = "_exports"; + } + let i = 0; + const original = input; + while (context.usedSymbolNames!.has(input)) { + i++; + input = `${original}_${i}`; + } + context.usedSymbolNames!.set(input, true); + if (symbol) { + context.remappedSymbolNames!.set("" + getSymbolId(symbol), input); + } + return input; + } + + function getInternalSymbolName(symbol: Symbol, localName: string) { + if (context.remappedSymbolNames!.has("" + getSymbolId(symbol))) { + return context.remappedSymbolNames!.get("" + getSymbolId(symbol))!; + } + if (localName === InternalSymbolName.Default || localName === InternalSymbolName.Class || localName === InternalSymbolName.Function) { + const flags = context.flags; + context.flags |= NodeBuilderFlags.InInitialEntityName; + const nameCandidate = getNameOfSymbolAsWritten(symbol, context); + context.flags = flags; + localName = isIdentifierText(nameCandidate, languageVersion) && !isStringANonContextualKeyword(nameCandidate) ? nameCandidate : getUnusedName(`_default`, symbol); + } + // The result of this is going to be used as the symbol's name - lock it in, so `getUnusedName` will also pick it up + context.remappedSymbolNames!.set("" + getSymbolId(symbol), localName); + return localName; + } + } } function typePredicateToString(typePredicate: TypePredicate, enclosingDeclaration?: Node, flags: TypeFormatFlags = TypeFormatFlags.UseAliasDefinedOutsideCurrentScope, writer?: EmitTextWriter): string { @@ -4820,6 +6136,8 @@ namespace ts { typeParameterSymbolList?: Map; typeParameterNames?: Map; typeParameterNamesByText?: Map; + usedSymbolNames?: Map; + remappedSymbolNames?: Map; } function isDefaultBindingContext(location: Node) { @@ -5011,7 +6329,10 @@ namespace ts { exportSymbol = getTargetOfExportSpecifier(node.parent, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias); } let result: Node[] | undefined; + let visited: Map | undefined; if (exportSymbol) { + visited = createMap(); + visited.set("" + getSymbolId(exportSymbol), true); buildVisibleNodeList(exportSymbol.declarations); } return result; @@ -5033,7 +6354,9 @@ namespace ts { const firstIdentifier = getFirstIdentifier(internalModuleReference); const importSymbol = resolveName(declaration, firstIdentifier.escapedText, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, undefined, undefined, /*isUse*/ false); - if (importSymbol) { + const id = importSymbol && "" + getSymbolId(importSymbol); + if (importSymbol && !visited!.has(id!)) { + visited!.set(id!, true); buildVisibleNodeList(importSymbol.declarations); } } @@ -5483,7 +6806,7 @@ namespace ts { isPropertyAccessExpression(declaration) ? isBinaryExpression(declaration.parent) ? declaration.parent : declaration : undefined; if (!expression) { - return errorType; + continue; // Non-assignment declaration merged in (eg, an Identifier to mark the thing as a namespace) - skip over it and pull type info from elsewhere } const kind = isPropertyAccessExpression(expression) ? getAssignmentDeclarationPropertyAccessKind(expression) : getAssignmentDeclarationKind(expression); @@ -5504,6 +6827,9 @@ namespace ts { } let type = jsdocType; if (!type) { + if (!length(types)) { + return errorType; // No types from any declarations :( + } let constructorTypes = definedInConstructor ? getConstructorDefinedThisAssignmentTypes(types!, symbol.declarations) : undefined; // use only the constructor types unless they were only assigned null | undefined (including widening variants) if (definedInMethod) { @@ -5902,6 +7228,9 @@ namespace ts { else if (isEnumMember(declaration)) { type = getTypeOfEnumMember(symbol); } + else if (isAccessor(declaration)) { + type = resolveTypeOfAccessors(symbol); + } else { return Debug.fail("Unhandled declaration kind! " + Debug.formatSyntaxKind(declaration.kind) + " for " + Debug.formatSymbol(symbol)); } @@ -5950,6 +7279,23 @@ namespace ts { } function getTypeOfAccessorsWorker(symbol: Symbol): Type { + if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { + return errorType; + } + + let type = resolveTypeOfAccessors(symbol); + + if (!popTypeResolution()) { + type = anyType; + if (noImplicitAny) { + const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); + error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); + } + } + return type; + } + + function resolveTypeOfAccessors(symbol: Symbol) { const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor); @@ -5959,28 +7305,21 @@ namespace ts { return jsDocType; } } - - if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) { - return errorType; - } - - let type: Type; - // First try to see if the user specified a return type on the get-accessor. const getterReturnType = getAnnotatedAccessorType(getter); if (getterReturnType) { - type = getterReturnType; + return getterReturnType; } else { // If the user didn't specify a return type, try to use the set-accessor's parameter type. const setterParameterType = getAnnotatedAccessorType(setter); if (setterParameterType) { - type = setterParameterType; + return setterParameterType; } else { // If there are no specified types, try to infer it from the body of the get accessor if it exists. if (getter && getter.body) { - type = getReturnTypeFromBody(getter); + return getReturnTypeFromBody(getter); } // Otherwise, fall back to 'any'. else { @@ -5993,18 +7332,10 @@ namespace ts { Debug.assert(!!getter, "there must existed getter as we are current checking either setter or getter in this function"); errorOrSuggestion(noImplicitAny, getter!, Diagnostics.Property_0_implicitly_has_type_any_because_its_get_accessor_lacks_a_return_type_annotation, symbolToString(symbol)); } - type = anyType; + return anyType; } } } - if (!popTypeResolution()) { - type = anyType; - if (noImplicitAny) { - const getter = getDeclarationOfKind(symbol, SyntaxKind.GetAccessor); - error(getter, Diagnostics._0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions, symbolToString(symbol)); - } - } - return type; } function getBaseTypeVariableOfClass(symbol: Symbol) { @@ -23470,7 +24801,7 @@ namespace ts { // resolveExternalModuleName will return undefined if the moduleReferenceExpression is not a string literal const moduleSymbol = resolveExternalModuleName(node, specifier); if (moduleSymbol) { - const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true); + const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true, /*suppressUsageError*/ false); if (esModuleSymbol) { return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol)); } @@ -30581,6 +31912,26 @@ namespace ts { } } + function getFirstNonModuleExportsIdentifier(node: EntityNameOrEntityNameExpression): Identifier { + switch (node.kind) { + case SyntaxKind.Identifier: + return node; + case SyntaxKind.QualifiedName: + do { + node = node.left; + } while (node.kind !== SyntaxKind.Identifier); + return node; + case SyntaxKind.PropertyAccessExpression: + do { + if (isModuleExportsPropertyAccessExpression(node.expression)) { + return node.name; + } + node = node.expression; + } while (node.kind !== SyntaxKind.Identifier); + return node; + } + } + function checkExternalImportOrExportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): boolean { const moduleName = getExternalModuleName(node); if (!moduleName || nodeIsMissing(moduleName)) { @@ -32566,6 +33917,15 @@ namespace ts { const parseNode = getParseTreeNode(node); const parseDecl = getParseTreeNode(decl); return !!parseNode && !!parseDecl && (isVariableDeclaration(parseDecl) || isBindingElement(parseDecl)) && isBindingCapturedByNode(parseNode, parseDecl); + }, + getDeclarationStatementsForSourceFile: (node, flags, tracker, bundled) => { + const n = getParseTreeNode(node) as SourceFile; + Debug.assert(n && n.kind === SyntaxKind.SourceFile, "Non-sourcefile node passed into getDeclarationsForSourceFile"); + const sym = getSymbolOfNode(node); + if (!sym) { + return !node.locals ? [] : nodeBuilder.symbolTableToDeclarationStatements(node.locals, node, flags, tracker, bundled); + } + return !sym.exports ? [] : nodeBuilder.symbolTableToDeclarationStatements(sym.exports, node, flags, tracker, bundled); } }; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 73e0261670fd5..8703f3de8f7c2 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1552,6 +1552,14 @@ namespace ts { return fn ? fn.bind(obj) : undefined; } + export function mapMap(map: Map, f: (t: T, key: string) => [string, U]): Map; + export function mapMap(map: UnderscoreEscapedMap, f: (t: T, key: __String) => [string, U]): Map; + export function mapMap(map: Map | UnderscoreEscapedMap, f: ((t: T, key: string) => [string, U]) | ((t: T, key: __String) => [string, U])): Map { + const result = createMap(); + map.forEach((t: T, key: string & __String) => result.set(...(f(t, key)))); + return result; + } + export interface MultiMap extends Map { /** * Adds the value to an array of values associated with the key, and returns the array. diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 78700a9476cef..6e8617d59389b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4587,6 +4587,14 @@ "category": "Error", "code": 9004 }, + "Declaration emit for this file requires using private name '{0}'. An explicit type annotation may unblock declaration emit.": { + "category": "Error", + "code": 9005 + }, + "Declaration emit for this file requires using private name '{0}' from module '{1}'. An explicit type annotation may unblock declaration emit.": { + "category": "Error", + "code": 9006 + }, "JSX attributes must only be assigned a non-empty 'expression'.": { "category": "Error", "code": 17000 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2ed08f29e212c..36a70ec7d2562 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -96,9 +96,7 @@ namespace ts { comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === Comparison.EqualTo; const jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath; const sourceMapFilePath = !jsFilePath || isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); - // For legacy reasons (ie, we have baselines capturing the behavior), js files don't report a .d.ts output path - this would only matter if `declaration` and `allowJs` were both on, which is currently an error - const isJs = isSourceFileJS(sourceFile); - const declarationFilePath = ((forceDtsPaths || getEmitDeclarations(options)) && !isJs) ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; + const declarationFilePath = (forceDtsPaths || getEmitDeclarations(options)) ? getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; const declarationMapPath = declarationFilePath && getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath: undefined }; } @@ -146,7 +144,7 @@ namespace ts { /* @internal */ export function getOutputDeclarationFileName(inputFileName: string, configFile: ParsedCommandLine, ignoreCase: boolean) { - Debug.assert(!fileExtensionIs(inputFileName, Extension.Dts) && hasTSFileExtension(inputFileName)); + Debug.assert(!fileExtensionIs(inputFileName, Extension.Dts)); return changeExtension( getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir), Extension.Dts @@ -199,7 +197,7 @@ namespace ts { if (js && configFile.options.sourceMap) { addOutput(`${js}.map`); } - if (getEmitDeclarations(configFile.options) && hasTSFileExtension(inputFileName)) { + if (getEmitDeclarations(configFile.options)) { const dts = getOutputDeclarationFileName(inputFileName, configFile, ignoreCase); addOutput(dts); if (configFile.options.declarationMap) { @@ -248,7 +246,7 @@ namespace ts { const jsFilePath = getOutputJSFileName(inputFileName, configFile, ignoreCase); if (jsFilePath) return jsFilePath; if (fileExtensionIs(inputFileName, Extension.Json)) continue; - if (getEmitDeclarations(configFile.options) && hasTSFileExtension(inputFileName)) { + if (getEmitDeclarations(configFile.options)) { return getOutputDeclarationFileName(inputFileName, configFile, ignoreCase); } } @@ -395,17 +393,16 @@ namespace ts { declarationFilePath: string | undefined, declarationMapPath: string | undefined, relativeToBuildInfo: (path: string) => string) { - if (!sourceFileOrBundle || !(declarationFilePath && !isInJSFile(sourceFileOrBundle))) { + if (!sourceFileOrBundle || !declarationFilePath) { return; } const sourceFiles = isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles; // Setup and perform the transformation to retrieve declarations from the input files - const nonJsFiles = filter(sourceFiles, isSourceFileNotJS); - const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(nonJsFiles, !isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : nonJsFiles; + const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(sourceFiles, !isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : sourceFiles; if (emitOnlyDtsFiles && !getEmitDeclarations(compilerOptions)) { // Checker wont collect the linked aliases since thats only done when declaration is enabled. // Do that here when emitting only dts files - nonJsFiles.forEach(collectLinkedAliases); + sourceFiles.forEach(collectLinkedAliases); } const declarationTransform = transformNodes(resolver, host, compilerOptions, inputListOrBundle, declarationTransformers, /*allowDtsFiles*/ false); if (length(declarationTransform.diagnostics)) { @@ -659,6 +656,7 @@ namespace ts { getAllAccessorDeclarations: notImplemented, getSymbolOfExternalModuleSpecifier: notImplemented, isBindingCapturedByNode: notImplemented, + getDeclarationStatementsForSourceFile: notImplemented, }; /*@internal*/ diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index a4f780185e91e..95220fec0be62 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -2259,6 +2259,11 @@ namespace ts { : node; } + /* @internal */ + export function createEmptyExports() { + return createExportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createNamedExports([]), /*moduleSpecifier*/ undefined); + } + export function createNamedExports(elements: readonly ExportSpecifier[]) { const node = createSynthesizedNode(SyntaxKind.NamedExports); node.elements = createNodeArray(elements); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9bc91e423a4f2..98e7a96442c11 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -856,7 +856,7 @@ namespace ts { } else if (getEmitModuleKind(parsedRef.commandLine.options) === ModuleKind.None) { for (const fileName of parsedRef.commandLine.fileNames) { - if (!fileExtensionIs(fileName, Extension.Dts) && hasTSFileExtension(fileName)) { + if (!fileExtensionIs(fileName, Extension.Dts)) { processSourceFile(getOutputDeclarationFileName(fileName, parsedRef.commandLine, !host.useCaseSensitiveFileNames()), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined); } } @@ -2448,8 +2448,8 @@ namespace ts { } function getProjectReferenceRedirectProject(fileName: string) { - // Ignore dts or any of the non ts files - if (!resolvedProjectReferences || !resolvedProjectReferences.length || fileExtensionIs(fileName, Extension.Dts) || !fileExtensionIsOneOf(fileName, supportedTSExtensions)) { + // Ignore dts + if (!resolvedProjectReferences || !resolvedProjectReferences.length || fileExtensionIs(fileName, Extension.Dts)) { return undefined; } @@ -2510,7 +2510,7 @@ namespace ts { } else { forEach(resolvedRef.commandLine.fileNames, fileName => { - if (!fileExtensionIs(fileName, Extension.Dts) && hasTSFileExtension(fileName)) { + if (!fileExtensionIs(fileName, Extension.Dts)) { const outputDts = getOutputDeclarationFileName(fileName, resolvedRef.commandLine, host.useCaseSensitiveFileNames()); mapFromToProjectReferenceRedirectSource!.set(toPath(outputDts), fileName); } @@ -3077,10 +3077,6 @@ namespace ts { createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_when_option_target_is_ES3, "useDefineForClassFields"); } - if (!options.noEmit && options.allowJs && getEmitDeclarations(options)) { - createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", getEmitDeclarationOptionName(options)); - } - if (options.checkJs && !options.allowJs) { programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1, "checkJs", "allowJs")); } @@ -3425,9 +3421,6 @@ namespace ts { return resolveConfigFileProjectName(passedInRef.path); } - function getEmitDeclarationOptionName(options: CompilerOptions) { - return options.declaration ? "declaration" : "composite"; - } /* @internal */ /** * Returns a DiagnosticMessage if we won't include a resolved module due to its extension. diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index add17449edf3d..6d6016fe109ae 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1,11 +1,8 @@ /*@internal*/ namespace ts { export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, file: SourceFile | undefined): DiagnosticWithLocation[] | undefined { - if (file && isSourceFileJS(file)) { - return []; // No declaration diagnostics for js for now - } const compilerOptions = host.getCompilerOptions(); - const result = transformNodes(resolver, host, compilerOptions, file ? [file] : filter(host.getSourceFiles(), isSourceFileNotJS), [transformDeclarations], /*allowDtsFiles*/ false); + const result = transformNodes(resolver, host, compilerOptions, file ? [file] : host.getSourceFiles(), [transformDeclarations], /*allowDtsFiles*/ false); return result.diagnostics; } @@ -190,15 +187,24 @@ namespace ts { } } - function createEmptyExports() { - return createExportDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createNamedExports([]), /*moduleSpecifier*/ undefined); + function transformDeclarationsForJS(sourceFile: SourceFile, bundled?: boolean) { + const oldDiag = getSymbolAccessibilityDiagnostic; + getSymbolAccessibilityDiagnostic = (s) => ({ + diagnosticMessage: s.errorModuleName + ? Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_from_module_1_An_explicit_type_annotation_may_unblock_declaration_emit + : Diagnostics.Declaration_emit_for_this_file_requires_using_private_name_0_An_explicit_type_annotation_may_unblock_declaration_emit, + errorNode: s.errorNode || sourceFile + }); + const result = resolver.getDeclarationStatementsForSourceFile(sourceFile, declarationEmitNodeBuilderFlags, symbolTracker, bundled); + getSymbolAccessibilityDiagnostic = oldDiag; + return result; } function transformRoot(node: Bundle): Bundle; function transformRoot(node: SourceFile): SourceFile; function transformRoot(node: SourceFile | Bundle): SourceFile | Bundle; function transformRoot(node: SourceFile | Bundle) { - if (node.kind === SyntaxKind.SourceFile && (node.isDeclarationFile || isSourceFileJS(node))) { + if (node.kind === SyntaxKind.SourceFile && node.isDeclarationFile) { return node; } @@ -209,7 +215,7 @@ namespace ts { let hasNoDefaultLib = false; const bundle = createBundle(map(node.sourceFiles, sourceFile => { - if (sourceFile.isDeclarationFile || isSourceFileJS(sourceFile)) return undefined!; // Omit declaration files from bundle results, too // TODO: GH#18217 + if (sourceFile.isDeclarationFile) return undefined!; // Omit declaration files from bundle results, too // TODO: GH#18217 hasNoDefaultLib = hasNoDefaultLib || sourceFile.hasNoDefaultLib; currentSourceFile = sourceFile; enclosingDeclaration = sourceFile; @@ -221,10 +227,10 @@ namespace ts { resultHasScopeMarker = false; collectReferences(sourceFile, refs); collectLibs(sourceFile, libs); - if (isExternalModule(sourceFile)) { + if (isExternalOrCommonJsModule(sourceFile) || isJsonSourceFile(sourceFile)) { resultHasExternalModuleIndicator = false; // unused in external module bundle emit (all external modules are within module blocks, therefore are known to be modules) needsDeclare = false; - const statements = visitNodes(sourceFile.statements, visitDeclarationStatements); + const statements = isSourceFileJS(sourceFile) ? createNodeArray(transformDeclarationsForJS(sourceFile, /*bundled*/ true)) : visitNodes(sourceFile.statements, visitDeclarationStatements); const newFile = updateSourceFileNode(sourceFile, [createModuleDeclaration( [], [createModifier(SyntaxKind.DeclareKeyword)], @@ -234,7 +240,7 @@ namespace ts { return newFile; } needsDeclare = true; - const updated = visitNodes(sourceFile.statements, visitDeclarationStatements); + const updated = isSourceFileJS(sourceFile) ? createNodeArray(transformDeclarationsForJS(sourceFile)) : visitNodes(sourceFile.statements, visitDeclarationStatements); return updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []); } ), mapDefined(node.prepends, prepend => { @@ -276,12 +282,19 @@ namespace ts { const references: FileReference[] = []; const outputFilePath = getDirectoryPath(normalizeSlashes(getOutputPathsFor(node, host, /*forceDtsPaths*/ true).declarationFilePath!)); const referenceVisitor = mapReferencesIntoArray(references, outputFilePath); - const statements = visitNodes(node.statements, visitDeclarationStatements); - let combinedStatements = setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements); - refs.forEach(referenceVisitor); - emittedImports = filter(combinedStatements, isAnyImportSyntax); - if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) { - combinedStatements = setTextRange(createNodeArray([...combinedStatements, createEmptyExports()]), combinedStatements); + let combinedStatements: NodeArray; + if (isSourceFileJS(currentSourceFile)) { + combinedStatements = createNodeArray(transformDeclarationsForJS(node)); + emittedImports = filter(combinedStatements, isAnyImportSyntax); + } + else { + const statements = visitNodes(node.statements, visitDeclarationStatements); + combinedStatements = setTextRange(createNodeArray(transformAndReplaceLatePaintedStatements(statements)), node.statements); + refs.forEach(referenceVisitor); + emittedImports = filter(combinedStatements, isAnyImportSyntax); + if (isExternalModule(node) && (!resultHasExternalModuleIndicator || (needsScopeFixMarker && !resultHasScopeMarker))) { + combinedStatements = setTextRange(createNodeArray([...combinedStatements, createEmptyExports()]), combinedStatements); + } } const updated = updateSourceFileNode(node, combinedStatements, /*isDeclarationFile*/ true, references, getFileReferencesForUsedTypeReferences(), node.hasNoDefaultLib, getLibReferences()); updated.exportedModulesFromDeclarationEmit = exportedModulesFromDeclarationEmit; @@ -755,15 +768,6 @@ namespace ts { } } - function isExternalModuleIndicator(result: LateVisibilityPaintedStatement | ExportAssignment) { - // Exported top-level member indicates moduleness - return isAnyImportOrReExport(result) || isExportAssignment(result) || hasModifier(result, ModifierFlags.Export); - } - - function needsScopeMarker(result: LateVisibilityPaintedStatement | ExportAssignment) { - return !isAnyImportOrReExport(result) && !isExportAssignment(result) && !hasModifier(result, ModifierFlags.Export) && !isAmbientModule(result); - } - function visitDeclarationSubtree(input: Node): VisitResult { if (shouldStripInternal(input)) return; if (isDeclaration(input)) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 28d5fdbb1c967..73d3785d28643 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3734,6 +3734,7 @@ namespace ts { getAllAccessorDeclarations(declaration: AccessorDeclaration): AllAccessorDeclarations; getSymbolOfExternalModuleSpecifier(node: StringLiteralLike): Symbol | undefined; isBindingCapturedByNode(node: Node, decl: VariableDeclaration | BindingElement): boolean; + getDeclarationStatementsForSourceFile(node: SourceFile, flags: NodeBuilderFlags, tracker: SymbolTracker, bundled?: boolean): Statement[] | undefined; } export const enum SymbolFlags { @@ -3814,6 +3815,12 @@ namespace ts { ClassMember = Method | Accessor | Property, + /* @internal */ + ExportSupportsDefaultModifier = Class | Function | Interface, + + /* @internal */ + ExportDoesNotSupportDefaultModifier = ~ExportSupportsDefaultModifier, + /* @internal */ // The set of things we consider semantically classifiable. Used to speed up the LS during // classification. @@ -3877,6 +3884,7 @@ namespace ts { variances?: VarianceFlags[]; // Alias symbol type argument variance cache deferralConstituents?: Type[]; // Calculated list of constituents for a deferred type deferralParent?: Type; // Source union/intersection of a deferred type + cjsExportMerged?: Symbol; // Version of the symbol with all non export= exports merged with the export= target } /* @internal */ @@ -6024,7 +6032,7 @@ namespace ts { // Called when the symbol writer encounters a symbol to write. Currently only used by the // declaration emitter to help determine if it should patch up the final declaration file // with import statements it previously saw (but chose not to emit). - trackSymbol?(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void; + trackSymbol?(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags): void; reportInaccessibleThisError?(): void; reportPrivateInBaseOfClassExpression?(propertyName: string): void; reportInaccessibleUniqueSymbolError?(): void; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a00b7c2d7ad97..bc3f886e9e463 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2606,6 +2606,8 @@ namespace ts { // export = // export default // module.exports = + // {} + // {name: } export function isAliasSymbolDeclaration(node: Node): boolean { return node.kind === SyntaxKind.ImportEqualsDeclaration || node.kind === SyntaxKind.NamespaceExportDeclaration || @@ -2614,14 +2616,30 @@ namespace ts { node.kind === SyntaxKind.ImportSpecifier || node.kind === SyntaxKind.ExportSpecifier || node.kind === SyntaxKind.ExportAssignment && exportAssignmentIsAlias(node) || - isBinaryExpression(node) && getAssignmentDeclarationKind(node) === AssignmentDeclarationKind.ModuleExports && exportAssignmentIsAlias(node); + isBinaryExpression(node) && getAssignmentDeclarationKind(node) === AssignmentDeclarationKind.ModuleExports && exportAssignmentIsAlias(node) || + isPropertyAccessExpression(node) && isBinaryExpression(node.parent) && node.parent.left === node && node.parent.operatorToken.kind === SyntaxKind.EqualsToken && isAliasableExpression(node.parent.right) || + node.kind === SyntaxKind.ShorthandPropertyAssignment || + node.kind === SyntaxKind.PropertyAssignment && isAliasableExpression((node as PropertyAssignment).initializer); } - export function exportAssignmentIsAlias(node: ExportAssignment | BinaryExpression): boolean { - const e = isExportAssignment(node) ? node.expression : node.right; + function isAliasableExpression(e: Expression) { return isEntityNameExpression(e) || isClassExpression(e); } + export function exportAssignmentIsAlias(node: ExportAssignment | BinaryExpression): boolean { + const e = getExportAssignmentExpression(node); + return isAliasableExpression(e); + } + + export function getExportAssignmentExpression(node: ExportAssignment | BinaryExpression): Expression { + return isExportAssignment(node) ? node.expression : node.right; + } + + export function getPropertyAssignmentAliasLikeExpression(node: PropertyAssignment | ShorthandPropertyAssignment | PropertyAccessExpression): Expression { + return node.kind === SyntaxKind.ShorthandPropertyAssignment ? node.name : node.kind === SyntaxKind.PropertyAssignment ? node.initializer : + (node.parent as BinaryExpression).right; + } + export function getEffectiveBaseTypeNode(node: ClassLikeDeclaration | InterfaceDeclaration) { const baseType = getClassExtendsHeritageElement(node); if (baseType && isInJSFile(node)) { @@ -2699,6 +2717,11 @@ namespace ts { return token !== undefined && isNonContextualKeyword(token); } + export function isStringAKeyword(name: string) { + const token = stringToToken(name); + return token !== undefined && isKeyword(token); + } + export function isIdentifierANonContextualKeyword({ originalKeywordKind }: Identifier): boolean { return !!originalKeywordKind && !isContextualKeyword(originalKeywordKind); } @@ -3450,11 +3473,17 @@ namespace ts { }; } - export function getResolvedExternalModuleName(host: EmitHost, file: SourceFile, referenceFile?: SourceFile): string { + export interface ResolveModuleNameResolutionHost { + getCanonicalFileName(p: string): string; + getCommonSourceDirectory(): string; + getCurrentDirectory(): string; + } + + export function getResolvedExternalModuleName(host: ResolveModuleNameResolutionHost, file: SourceFile, referenceFile?: SourceFile): string { return file.moduleName || getExternalModuleNameFromPath(host, file.fileName, referenceFile && referenceFile.fileName); } - export function getExternalModuleNameFromDeclaration(host: EmitHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): string | undefined { + export function getExternalModuleNameFromDeclaration(host: ResolveModuleNameResolutionHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): string | undefined { const file = resolver.getExternalModuleFileFromDeclaration(declaration); if (!file || file.isDeclarationFile) { return undefined; @@ -3465,7 +3494,7 @@ namespace ts { /** * Resolves a local path to a path which is absolute to the base of the emit */ - export function getExternalModuleNameFromPath(host: EmitHost, fileName: string, referencePath?: string): string { + export function getExternalModuleNameFromPath(host: ResolveModuleNameResolutionHost, fileName: string, referencePath?: string): string { const getCanonicalFileName = (f: string) => host.getCanonicalFileName(f); const dir = toPath(referencePath ? getDirectoryPath(referencePath) : host.getCommonSourceDirectory(), host.getCurrentDirectory(), getCanonicalFileName); const filePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); @@ -5224,6 +5253,17 @@ namespace ts { return name && isIdentifier(name) ? name : undefined; } + /** @internal */ + export function nodeHasName(statement: Node, name: Identifier) { + if (isNamedDeclaration(statement) && isIdentifier(statement.name) && idText(statement.name as Identifier) === idText(name)) { + return true; + } + if (isVariableStatement(statement) && some(statement.declarationList.declarations, d => nodeHasName(d, name))) { + return true; + } + return false; + } + export function getNameOfJSDocTypedef(declaration: JSDocTypedefTag): Identifier | undefined { return declaration.name || nameForNamelessJSDocTypedef(declaration); } @@ -6145,7 +6185,7 @@ namespace ts { return node.kind === SyntaxKind.JSDocTypeExpression; } - export function isJSDocAllType(node: JSDocAllType): node is JSDocAllType { + export function isJSDocAllType(node: Node): node is JSDocAllType { return node.kind === SyntaxKind.JSDocAllType; } @@ -6762,6 +6802,27 @@ namespace ts { return false; } + /* @internal */ + export function isScopeMarker(node: Node) { + return isExportAssignment(node) || isExportDeclaration(node); + } + + /* @internal */ + export function hasScopeMarker(statements: readonly Statement[]) { + return some(statements, isScopeMarker); + } + + /* @internal */ + export function needsScopeMarker(result: Statement) { + return !isAnyImportOrReExport(result) && !isExportAssignment(result) && !hasModifier(result, ModifierFlags.Export) && !isAmbientModule(result); + } + + /* @internal */ + export function isExternalModuleIndicator(result: Statement) { + // Exported top-level member indicates moduleness + return isAnyImportOrReExport(result) || isExportAssignment(result) || hasModifier(result, ModifierFlags.Export); + } + /* @internal */ export function isForInOrOfStatement(node: Node): node is ForInOrOfStatement { return node.kind === SyntaxKind.ForInStatement || node.kind === SyntaxKind.ForOfStatement; diff --git a/src/harness/compiler.ts b/src/harness/compiler.ts index 880163a10f631..19d6545c999fa 100644 --- a/src/harness/compiler.ts +++ b/src/harness/compiler.ts @@ -219,14 +219,19 @@ namespace compiler { return vpath.changeExtension(path, ext); } - public getNumberOfJsFiles() { - let count = this.js.size; - this.js.forEach(document => { - if (ts.fileExtensionIs(document.file, ts.Extension.Json)) { - count--; - } - }); - return count; + public getNumberOfJsFiles(includeJson: boolean) { + if (includeJson) { + return this.js.size; + } + else { + let count = this.js.size; + this.js.forEach(document => { + if (ts.fileExtensionIs(document.file, ts.Extension.Json)) { + count--; + } + }); + return count; + } } } diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 35af677836347..e93033e126bdc 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -888,7 +888,7 @@ namespace Harness { throw new Error("Only declaration files should be generated when emitDeclarationOnly:true"); } } - else if (result.dts.size !== result.getNumberOfJsFiles()) { + else if (result.dts.size !== result.getNumberOfJsFiles(/*includeJson*/ true)) { throw new Error("There were no errors and declFiles generated did not match number of js files generated"); } } @@ -907,7 +907,7 @@ namespace Harness { if (vpath.isDeclaration(file.unitName) || vpath.isJson(file.unitName)) { dtsFiles.push(file); } - else if (vpath.isTypeScript(file.unitName)) { + else if (vpath.isTypeScript(file.unitName) || (vpath.isJavaScript(file.unitName) && options.allowJs)) { const declFile = findResultCodeFile(file.unitName); if (declFile && !findUnit(declFile.file, declInputFiles) && !findUnit(declFile.file, declOtherFiles)) { dtsFiles.push({ unitName: declFile.file, content: utils.removeByteOrderMark(declFile.text) }); @@ -1269,7 +1269,7 @@ namespace Harness { return; } else if (options.sourceMap || declMaps) { - if (result.maps.size !== (result.getNumberOfJsFiles() * (declMaps && options.sourceMap ? 2 : 1))) { + if (result.maps.size !== ((options.sourceMap ? result.getNumberOfJsFiles(/*includeJson*/ false) : 0) + (declMaps ? result.getNumberOfJsFiles(/*includeJson*/ true) : 0))) { throw new Error("Number of sourcemap files should be same as js files."); } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 5f59cef602bb3..18b867fbe0f92 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1971,8 +1971,7 @@ namespace ts { const notAccessible = () => { typeIsAccessible = false; }; const res = checker.typeToTypeNode(type, enclosingScope, /*flags*/ undefined, { trackSymbol: (symbol, declaration, meaning) => { - // TODO: GH#18217 - typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning!, /*shouldComputeAliasToMarkVisible*/ false).accessibility === SymbolAccessibility.Accessible; + typeIsAccessible = typeIsAccessible && checker.isSymbolAccessible(symbol, declaration, meaning, /*shouldComputeAliasToMarkVisible*/ false).accessibility === SymbolAccessibility.Accessible; }, reportInaccessibleThisError: notAccessible, reportPrivateInBaseOfClassExpression: notAccessible, diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 49272d6c1b3cc..28f2af9eeb9f6 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -99,6 +99,7 @@ "unittests/tsbuild/emptyFiles.ts", "unittests/tsbuild/graphOrdering.ts", "unittests/tsbuild/inferredTypeFromTransitiveModule.ts", + "unittests/tsbuild/javascriptProjectEmit.ts", "unittests/tsbuild/lateBoundSymbol.ts", "unittests/tsbuild/missingExtendedFile.ts", "unittests/tsbuild/moduleSpecifiers.ts", diff --git a/src/testRunner/unittests/tsbuild/javascriptProjectEmit.ts b/src/testRunner/unittests/tsbuild/javascriptProjectEmit.ts new file mode 100644 index 0000000000000..fb580a14d45ad --- /dev/null +++ b/src/testRunner/unittests/tsbuild/javascriptProjectEmit.ts @@ -0,0 +1,286 @@ +namespace ts { + describe("unittests:: tsbuild:: javascriptProjectEmit:: loads js-based projects and emits them correctly", () => { + verifyTsc({ + scenario: "javascriptProjectEmit", + subScenario: `loads js-based projects and emits them correctly`, + fs: () => loadProjectFromFiles({ + "/src/common/nominal.js": utils.dedent` + /** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + module.exports = {}; + `, + "/src/common/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "include": ["nominal.js"] + }`, + "/src/sub-project/index.js": utils.dedent` + import { Nominal } from '../common/nominal'; + + /** + * @typedef {Nominal} MyNominal + */ + `, + "/src/sub-project/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "../common" } + ], + "include": ["./index.js"] + }`, + "/src/sub-project-2/index.js": utils.dedent` + import { MyNominal } from '../sub-project/index'; + + const variable = { + key: /** @type {MyNominal} */('value'), + }; + + /** + * @return {keyof typeof variable} + */ + export function getVar() { + return 'key'; + } + `, + "/src/sub-project-2/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "../sub-project" } + ], + "include": ["./index.js"] + }`, + "/src/tsconfig.json": utils.dedent` + { + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./sub-project" }, + { "path": "./sub-project-2" } + ], + "include": [] + }`, + "/src/tsconfig.base.json": utils.dedent` + { + "compilerOptions": { + "skipLibCheck": true, + "rootDir": "./", + "outDir": "../lib", + "allowJs": true, + "checkJs": true, + "declaration": true + } + }`, + }, symbolLibContent), + commandLineArgs: ["-b", "/src"] + }); + }); + + describe("unittests:: tsbuild:: javascriptProjectEmit:: loads outfile js projects and concatenates them correctly", () => { + let projFs: vfs.FileSystem; + before(() => { + projFs = loadProjectFromFiles({ + "/src/common/nominal.js": utils.dedent` + /** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + `, + "/src/common/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outFile": "common.js" + }, + "include": ["nominal.js"] + }`, + "/src/sub-project/index.js": utils.dedent` + /** + * @typedef {Nominal} MyNominal + */ + const c = /** @type {*} */(null); + `, + "/src/sub-project/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outFile": "sub-project.js" + }, + "references": [ + { "path": "../common", "prepend": true } + ], + "include": ["./index.js"] + }`, + "/src/sub-project-2/index.js": utils.dedent` + const variable = { + key: /** @type {MyNominal} */('value'), + }; + + /** + * @return {keyof typeof variable} + */ + function getVar() { + return 'key'; + } + `, + "/src/sub-project-2/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true, + "outFile": "sub-project-2.js" + }, + "references": [ + { "path": "../sub-project", "prepend": true } + ], + "include": ["./index.js"] + }`, + "/src/tsconfig.json": utils.dedent` + { + "compilerOptions": { + "composite": true, + "outFile": "src.js" + }, + "references": [ + { "path": "./sub-project", "prepend": true }, + { "path": "./sub-project-2", "prepend": true } + ], + "include": [] + }`, + "/src/tsconfig.base.json": utils.dedent` + { + "compilerOptions": { + "skipLibCheck": true, + "rootDir": "./", + "allowJs": true, + "checkJs": true, + "declaration": true + } + }`, + }, symbolLibContent); + }); + after(() => { + projFs = undefined!; + }); + verifyTsc({ + scenario: "javascriptProjectEmit", + subScenario: `loads outfile js projects and concatenates them correctly`, + fs: () => projFs, + commandLineArgs: ["-b", "/src"] + }); + verifyTscIncrementalEdits({ + scenario: "javascriptProjectEmit", + subScenario: `modifies outfile js projects and concatenates them correctly`, + fs: () => projFs, + commandLineArgs: ["-b", "/src"], + incrementalScenarios: [{ + buildKind: BuildKind.IncrementalDtsUnchanged, + modifyFs: fs => replaceText(fs, "/src/sub-project/index.js", "null", "undefined") + }] + }); + }); + + describe("unittests:: tsbuild:: javascriptProjectEmit:: loads js-based projects with non-moved json files and emits them correctly", () => { + verifyTsc({ + scenario: "javascriptProjectEmit", + subScenario: `loads js-based projects with non-moved json files and emits them correctly`, + fs: () => loadProjectFromFiles({ + "/src/common/obj.json": utils.dedent` + { + "val": 42 + }`, + "/src/common/index.ts": utils.dedent` + import x = require("./obj.json"); + export = x; + `, + "/src/common/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": null + "composite": true + }, + "include": ["index.ts", "obj.json"] + }`, + "/src/sub-project/index.js": utils.dedent` + import mod from '../common'; + + export const m = mod; + `, + "/src/sub-project/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "../common" } + ], + "include": ["./index.js"] + }`, + "/src/sub-project-2/index.js": utils.dedent` + import { m } from '../sub-project/index'; + + const variable = { + key: m, + }; + + export function getVar() { + return variable; + } + `, + "/src/sub-project-2/tsconfig.json": utils.dedent` + { + "extends": "../tsconfig.base.json", + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "../sub-project" } + ], + "include": ["./index.js"] + }`, + "/src/tsconfig.json": utils.dedent` + { + "compilerOptions": { + "composite": true + }, + "references": [ + { "path": "./sub-project" }, + { "path": "./sub-project-2" } + ], + "include": [] + }`, + "/src/tsconfig.base.json": utils.dedent` + { + "compilerOptions": { + "skipLibCheck": true, + "rootDir": "./", + "outDir": "../out", + "allowJs": true, + "checkJs": true, + "resolveJsonModule": true, + "esModuleInterop": true, + "declaration": true + } + }`, + }, symbolLibContent), + commandLineArgs: ["-b", "/src"] + }); + }); +} diff --git a/src/testRunner/unittests/tsbuild/resolveJsonModule.ts b/src/testRunner/unittests/tsbuild/resolveJsonModule.ts index 71ae0d4c86e80..4d36bab67bae2 100644 --- a/src/testRunner/unittests/tsbuild/resolveJsonModule.ts +++ b/src/testRunner/unittests/tsbuild/resolveJsonModule.ts @@ -52,7 +52,12 @@ namespace ts { export default hello.hello`); const allExpectedOutputs = ["/src/dist/src/index.js", "/src/dist/src/index.d.ts", "/src/dist/src/index.json"]; - verifyProjectWithResolveJsonModuleWithFs(fs, "/src/tsconfig_withIncludeOfJson.json", allExpectedOutputs); + verifyProjectWithResolveJsonModuleWithFs( + fs, + "/src/tsconfig_withIncludeOfJson.json", + allExpectedOutputs, + errorDiagnostic([Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files, "/src/dist/src/index.d.ts"]) + ); }); it("with resolveJsonModule and files containing json file", () => { diff --git a/src/testRunner/unittests/tscWatch/programUpdates.ts b/src/testRunner/unittests/tscWatch/programUpdates.ts index 1aa5107f7279c..ed2a15c9a1410 100644 --- a/src/testRunner/unittests/tscWatch/programUpdates.ts +++ b/src/testRunner/unittests/tscWatch/programUpdates.ts @@ -885,8 +885,8 @@ namespace ts.tscWatch { // More comment`; const configFileContentAfterComment = ` "compilerOptions": { - "allowJs": true, - "declaration": true + "inlineSourceMap": true, + "mapRoot": "./" } }`; const configFileContentWithComment = configFileContentBeforeComment + configFileContentComment + configFileContentAfterComment; @@ -900,8 +900,9 @@ namespace ts.tscWatch { const host = createWatchedSystem(files); const watch = createWatchOfConfigFile(configFile.path, host); const errors = () => [ - getDiagnosticOfFile(watch().getCompilerOptions().configFile!, configFile.content.indexOf('"allowJs"'), '"allowJs"'.length, Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration"), - getDiagnosticOfFile(watch().getCompilerOptions().configFile!, configFile.content.indexOf('"declaration"'), '"declaration"'.length, Diagnostics.Option_0_cannot_be_specified_with_option_1, "allowJs", "declaration") + getDiagnosticOfFile(watch().getCompilerOptions().configFile!, configFile.content.indexOf('"inlineSourceMap"'), '"inlineSourceMap"'.length, Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap"), + getDiagnosticOfFile(watch().getCompilerOptions().configFile!, configFile.content.indexOf('"mapRoot"'), '"mapRoot"'.length, Diagnostics.Option_0_cannot_be_specified_with_option_1, "mapRoot", "inlineSourceMap"), + getDiagnosticOfFile(watch().getCompilerOptions().configFile!, configFile.content.indexOf('"mapRoot"'), '"mapRoot"'.length, Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "mapRoot", "sourceMap", "declarationMap") ]; const intialErrors = errors(); checkOutputErrorsInitial(host, intialErrors); diff --git a/src/testRunner/unittests/tsserver/projectErrors.ts b/src/testRunner/unittests/tsserver/projectErrors.ts index 86e772bebb526..bb60e48e3ad60 100644 --- a/src/testRunner/unittests/tsserver/projectErrors.ts +++ b/src/testRunner/unittests/tsserver/projectErrors.ts @@ -849,8 +849,8 @@ declare module '@custom/plugin' { // comment`; const configFileContentAfterComment = ` "compilerOptions": { - "allowJs": true, - "declaration": true + "inlineSourceMap": true, + "mapRoot": "./" } }`; const configFileContentWithComment = configFileContentBeforeComment + configFileContentComment + configFileContentAfterComment; @@ -874,7 +874,7 @@ declare module '@custom/plugin' { seq: 2, arguments: { file: configFile.path, projectFileName: projectName, includeLinePosition: true } }).response as readonly server.protocol.DiagnosticWithLinePosition[]; - assert.isTrue(diags.length === 2); + assert.isTrue(diags.length === 3); configFile.content = configFileContentWithoutCommentLine; host.reloadFS([file, configFile]); @@ -885,10 +885,11 @@ declare module '@custom/plugin' { seq: 2, arguments: { file: configFile.path, projectFileName: projectName, includeLinePosition: true } }).response as readonly server.protocol.DiagnosticWithLinePosition[]; - assert.isTrue(diagsAfterEdit.length === 2); + assert.isTrue(diagsAfterEdit.length === 3); verifyDiagnostic(diags[0], diagsAfterEdit[0]); verifyDiagnostic(diags[1], diagsAfterEdit[1]); + verifyDiagnostic(diags[2], diagsAfterEdit[2]); function verifyDiagnostic(beforeEditDiag: server.protocol.DiagnosticWithLinePosition, afterEditDiag: server.protocol.DiagnosticWithLinePosition) { assert.equal(beforeEditDiag.message, afterEditDiag.message); diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 3d055b9336aba..8f3095d2d5695 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3586,7 +3586,7 @@ declare namespace ts { function isUnparsedTextLike(node: Node): node is UnparsedTextLike; function isUnparsedNode(node: Node): node is UnparsedNode; function isJSDocTypeExpression(node: Node): node is JSDocTypeExpression; - function isJSDocAllType(node: JSDocAllType): node is JSDocAllType; + function isJSDocAllType(node: Node): node is JSDocAllType; function isJSDocUnknownType(node: Node): node is JSDocUnknownType; function isJSDocNullableType(node: Node): node is JSDocNullableType; function isJSDocNonNullableType(node: Node): node is JSDocNonNullableType; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 3bd00d6f2ebe5..a322d091a6ea4 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3586,7 +3586,7 @@ declare namespace ts { function isUnparsedTextLike(node: Node): node is UnparsedTextLike; function isUnparsedNode(node: Node): node is UnparsedNode; function isJSDocTypeExpression(node: Node): node is JSDocTypeExpression; - function isJSDocAllType(node: JSDocAllType): node is JSDocAllType; + function isJSDocAllType(node: Node): node is JSDocAllType; function isJSDocUnknownType(node: Node): node is JSDocUnknownType; function isJSDocNullableType(node: Node): node is JSDocNullableType; function isJSDocNonNullableType(node: Node): node is JSDocNonNullableType; diff --git a/tests/baselines/reference/augmentExportEquals3.types b/tests/baselines/reference/augmentExportEquals3.types index 87290d7415046..95ef09a899bea 100644 --- a/tests/baselines/reference/augmentExportEquals3.types +++ b/tests/baselines/reference/augmentExportEquals3.types @@ -10,7 +10,7 @@ namespace foo { >1 : 1 } export = foo; ->foo : typeof foo +>foo : typeof import("tests/cases/compiler/file1") === tests/cases/compiler/file2.ts === import x = require("./file1"); diff --git a/tests/baselines/reference/augmentExportEquals4.types b/tests/baselines/reference/augmentExportEquals4.types index 5e4574c815cc5..316c59cd498b3 100644 --- a/tests/baselines/reference/augmentExportEquals4.types +++ b/tests/baselines/reference/augmentExportEquals4.types @@ -10,7 +10,7 @@ namespace foo { >1 : 1 } export = foo; ->foo : foo +>foo : import("tests/cases/compiler/file1") === tests/cases/compiler/file2.ts === import x = require("./file1"); diff --git a/tests/baselines/reference/augmentExportEquals5.symbols b/tests/baselines/reference/augmentExportEquals5.symbols index 244073b6515d0..d7d14a1159faf 100644 --- a/tests/baselines/reference/augmentExportEquals5.symbols +++ b/tests/baselines/reference/augmentExportEquals5.symbols @@ -18,7 +18,7 @@ declare module "express" { function e(): e.Express; >e : Symbol(e, Decl(express.d.ts, 6, 26), Decl(express.d.ts, 7, 28), Decl(augmentation.ts, 1, 29)) >e : Symbol(e, Decl(express.d.ts, 6, 26), Decl(express.d.ts, 7, 28)) ->Express : Symbol(Express, Decl(express.d.ts, 52, 9)) +>Express : Symbol(e.Express, Decl(express.d.ts, 52, 9)) namespace e { >e : Symbol(e, Decl(express.d.ts, 6, 26), Decl(express.d.ts, 7, 28), Decl(augmentation.ts, 1, 29)) diff --git a/tests/baselines/reference/augmentExportEquals6.types b/tests/baselines/reference/augmentExportEquals6.types index 3a404744f0781..8e582c74de400 100644 --- a/tests/baselines/reference/augmentExportEquals6.types +++ b/tests/baselines/reference/augmentExportEquals6.types @@ -13,7 +13,7 @@ namespace foo { >a : any } export = foo; ->foo : foo +>foo : import("tests/cases/compiler/file1") === tests/cases/compiler/file2.ts === import x = require("./file1"); diff --git a/tests/baselines/reference/checkJsTypeDefNoUnusedLocalMarked.types b/tests/baselines/reference/checkJsTypeDefNoUnusedLocalMarked.types index e9385a7152df3..7fcf644cccd44 100644 --- a/tests/baselines/reference/checkJsTypeDefNoUnusedLocalMarked.types +++ b/tests/baselines/reference/checkJsTypeDefNoUnusedLocalMarked.types @@ -22,11 +22,11 @@ export = Foo; /** @typedef {(foo: Foo) => string} FooFun */ module.exports = /** @type {FooFun} */(void 0); ->module.exports = /** @type {FooFun} */(void 0) : (foo: typeof Foo) => string ->module.exports : (foo: typeof Foo) => string ->module : { "tests/cases/compiler/something": (foo: typeof Foo) => string; } ->exports : (foo: typeof Foo) => string ->(void 0) : (foo: typeof Foo) => string +>module.exports = /** @type {FooFun} */(void 0) : (foo: typeof import("tests/cases/compiler/file")) => string +>module.exports : (foo: typeof import("tests/cases/compiler/file")) => string +>module : { "tests/cases/compiler/something": (foo: typeof import("tests/cases/compiler/file")) => string; } +>exports : (foo: typeof import("tests/cases/compiler/file")) => string +>(void 0) : (foo: typeof import("tests/cases/compiler/file")) => string >void 0 : undefined >0 : 0 diff --git a/tests/baselines/reference/constructorFunctions2.types b/tests/baselines/reference/constructorFunctions2.types index 208a343375d26..b9a114604d82b 100644 --- a/tests/baselines/reference/constructorFunctions2.types +++ b/tests/baselines/reference/constructorFunctions2.types @@ -9,16 +9,16 @@ declare var module: any, exports: any; === tests/cases/conformance/salsa/index.js === const A = require("./other"); ->A : typeof A ->require("./other") : typeof A +>A : typeof import("tests/cases/conformance/salsa/other") +>require("./other") : typeof import("tests/cases/conformance/salsa/other") >require : (id: string) => any >"./other" : "./other" const a = new A().id; >a : number >new A().id : number ->new A() : A ->A : typeof A +>new A() : import("tests/cases/conformance/salsa/other") +>A : typeof import("tests/cases/conformance/salsa/other") >id : number const B = function() { this.id = 1; } diff --git a/tests/baselines/reference/declarationEmitNameConflicts.js b/tests/baselines/reference/declarationEmitNameConflicts.js index 57b11a88afbdd..693279a8edeb3 100644 --- a/tests/baselines/reference/declarationEmitNameConflicts.js +++ b/tests/baselines/reference/declarationEmitNameConflicts.js @@ -167,7 +167,7 @@ export declare module M.P { var a: typeof M.f; var b: typeof M.C; var c: typeof M.N; - var g: typeof M.c.g; + var g: typeof M.N.g; var d: typeof M.d; } export declare module M.Q { diff --git a/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.errors.txt b/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.errors.txt new file mode 100644 index 0000000000000..6e867246f6b42 --- /dev/null +++ b/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/input.ts(1,1): error TS2309: An export assignment cannot be used in a module with other exported elements. +tests/cases/compiler/input.ts(6,14): error TS2323: Cannot redeclare exported variable 'Sub'. + + +==== tests/cases/compiler/input.ts (2 errors) ==== + export = exports; + ~~~~~~~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + declare class exports { + constructor(p: number); + t: number; + } + export class Sub { + ~~~ +!!! error TS2323: Cannot redeclare exported variable 'Sub'. + instance!: { + t: number; + }; + } + declare namespace exports { + export { Sub }; + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.js b/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.js new file mode 100644 index 0000000000000..8afcf1649627a --- /dev/null +++ b/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.js @@ -0,0 +1,23 @@ +//// [input.ts] +export = exports; +declare class exports { + constructor(p: number); + t: number; +} +export class Sub { + instance!: { + t: number; + }; +} +declare namespace exports { + export { Sub }; +} + +//// [input.js] +"use strict"; +var Sub = /** @class */ (function () { + function Sub() { + } + return Sub; +}()); +module.exports = exports; diff --git a/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.symbols b/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.symbols new file mode 100644 index 0000000000000..05424e942d3e5 --- /dev/null +++ b/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/input.ts === +export = exports; +>exports : Symbol(exports, Decl(input.ts, 0, 17), Decl(input.ts, 9, 1)) + +declare class exports { +>exports : Symbol(exports, Decl(input.ts, 0, 17), Decl(input.ts, 9, 1)) + + constructor(p: number); +>p : Symbol(p, Decl(input.ts, 2, 16)) + + t: number; +>t : Symbol(exports.t, Decl(input.ts, 2, 27)) +} +export class Sub { +>Sub : Symbol(Sub, Decl(input.ts, 4, 1), Decl(input.ts, 4, 1)) + + instance!: { +>instance : Symbol(Sub.instance, Decl(input.ts, 5, 18)) + + t: number; +>t : Symbol(t, Decl(input.ts, 6, 16)) + + }; +} +declare namespace exports { +>exports : Symbol(exports, Decl(input.ts, 0, 17), Decl(input.ts, 9, 1)) + + export { Sub }; +>Sub : Symbol(exports.Sub, Decl(input.ts, 11, 12)) +} diff --git a/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.types b/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.types new file mode 100644 index 0000000000000..59a45d305eccc --- /dev/null +++ b/tests/baselines/reference/declarationFileNoCrashOnExtraExportModifier.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/input.ts === +export = exports; +>exports : import("tests/cases/compiler/input") + +declare class exports { +>exports : exports + + constructor(p: number); +>p : number + + t: number; +>t : number +} +export class Sub { +>Sub : Sub + + instance!: { +>instance : { t: number; } + + t: number; +>t : number + + }; +} +declare namespace exports { +>exports : typeof exports + + export { Sub }; +>Sub : typeof import("tests/cases/compiler/input").Sub +} diff --git a/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.js b/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.js new file mode 100644 index 0000000000000..a65a811fcfcc7 --- /dev/null +++ b/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.js @@ -0,0 +1,57 @@ +//// [tests/cases/compiler/declarationImportTypeAliasInferredAndEmittable.ts] //// + +//// [foo.ts] +class Conn { + constructor() { } + item = 3; + method() { } +} + +export = Conn; +//// [usage.ts] +type Conn = import("./foo"); +declare var x: Conn; + +export class Wrap { + connItem: number; + constructor(c = x) { + this.connItem = c.item; + } +} + + +//// [foo.js] +"use strict"; +var Conn = /** @class */ (function () { + function Conn() { + this.item = 3; + } + Conn.prototype.method = function () { }; + return Conn; +}()); +module.exports = Conn; +//// [usage.js] +"use strict"; +exports.__esModule = true; +var Wrap = /** @class */ (function () { + function Wrap(c) { + if (c === void 0) { c = x; } + this.connItem = c.item; + } + return Wrap; +}()); +exports.Wrap = Wrap; + + +//// [foo.d.ts] +declare class Conn { + constructor(); + item: number; + method(): void; +} +export = Conn; +//// [usage.d.ts] +export declare class Wrap { + connItem: number; + constructor(c?: import("./foo")); +} diff --git a/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.symbols b/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.symbols new file mode 100644 index 0000000000000..2e1e4ba25a329 --- /dev/null +++ b/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/foo.ts === +class Conn { +>Conn : Symbol(Conn, Decl(foo.ts, 0, 0)) + + constructor() { } + item = 3; +>item : Symbol(Conn.item, Decl(foo.ts, 1, 21)) + + method() { } +>method : Symbol(Conn.method, Decl(foo.ts, 2, 13)) +} + +export = Conn; +>Conn : Symbol(Conn, Decl(foo.ts, 0, 0)) + +=== tests/cases/compiler/usage.ts === +type Conn = import("./foo"); +>Conn : Symbol(Conn, Decl(usage.ts, 0, 0)) + +declare var x: Conn; +>x : Symbol(x, Decl(usage.ts, 1, 11)) +>Conn : Symbol(Conn, Decl(usage.ts, 0, 0)) + +export class Wrap { +>Wrap : Symbol(Wrap, Decl(usage.ts, 1, 20)) + + connItem: number; +>connItem : Symbol(Wrap.connItem, Decl(usage.ts, 3, 19)) + + constructor(c = x) { +>c : Symbol(c, Decl(usage.ts, 5, 16)) +>x : Symbol(x, Decl(usage.ts, 1, 11)) + + this.connItem = c.item; +>this.connItem : Symbol(Wrap.connItem, Decl(usage.ts, 3, 19)) +>this : Symbol(Wrap, Decl(usage.ts, 1, 20)) +>connItem : Symbol(Wrap.connItem, Decl(usage.ts, 3, 19)) +>c.item : Symbol(Conn.item, Decl(foo.ts, 1, 21)) +>c : Symbol(c, Decl(usage.ts, 5, 16)) +>item : Symbol(Conn.item, Decl(foo.ts, 1, 21)) + } +} + diff --git a/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.types b/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.types new file mode 100644 index 0000000000000..c125e9b1c08bc --- /dev/null +++ b/tests/baselines/reference/declarationImportTypeAliasInferredAndEmittable.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/foo.ts === +class Conn { +>Conn : Conn + + constructor() { } + item = 3; +>item : number +>3 : 3 + + method() { } +>method : () => void +} + +export = Conn; +>Conn : Conn + +=== tests/cases/compiler/usage.ts === +type Conn = import("./foo"); +>Conn : import("tests/cases/compiler/foo") + +declare var x: Conn; +>x : import("tests/cases/compiler/foo") + +export class Wrap { +>Wrap : Wrap + + connItem: number; +>connItem : number + + constructor(c = x) { +>c : import("tests/cases/compiler/foo") +>x : import("tests/cases/compiler/foo") + + this.connItem = c.item; +>this.connItem = c.item : number +>this.connItem : number +>this : this +>connItem : number +>c.item : number +>c : import("tests/cases/compiler/foo") +>item : number + } +} + diff --git a/tests/baselines/reference/duplicateExportAssignments.types b/tests/baselines/reference/duplicateExportAssignments.types index d9db21137591f..3a76cb669b632 100644 --- a/tests/baselines/reference/duplicateExportAssignments.types +++ b/tests/baselines/reference/duplicateExportAssignments.types @@ -29,7 +29,7 @@ export = y; === tests/cases/conformance/externalModules/foo3.ts === module x { ->x : typeof x +>x : typeof import("tests/cases/conformance/externalModules/foo3") export var x = 10; >x : number diff --git a/tests/baselines/reference/es5ExportEquals.types b/tests/baselines/reference/es5ExportEquals.types index f6273376a7cbe..83776f8fbc8bb 100644 --- a/tests/baselines/reference/es5ExportEquals.types +++ b/tests/baselines/reference/es5ExportEquals.types @@ -3,5 +3,5 @@ export function f() { } >f : typeof f export = f; ->f : { (): void; f: typeof import("tests/cases/compiler/es5ExportEquals").f; } +>f : { (): void; f: typeof import("tests/cases/compiler/es5ExportEquals"); } diff --git a/tests/baselines/reference/es6ExportEquals.types b/tests/baselines/reference/es6ExportEquals.types index eb8e59c31be6b..e4e5f1f69bca7 100644 --- a/tests/baselines/reference/es6ExportEquals.types +++ b/tests/baselines/reference/es6ExportEquals.types @@ -3,5 +3,5 @@ export function f() { } >f : typeof f export = f; ->f : { (): void; f: typeof import("tests/cases/compiler/es6ExportEquals").f; } +>f : { (): void; f: typeof import("tests/cases/compiler/es6ExportEquals"); } diff --git a/tests/baselines/reference/exportAssignmentAndDeclaration.types b/tests/baselines/reference/exportAssignmentAndDeclaration.types index 86b31844ab6d8..21eb5617e6271 100644 --- a/tests/baselines/reference/exportAssignmentAndDeclaration.types +++ b/tests/baselines/reference/exportAssignmentAndDeclaration.types @@ -15,5 +15,5 @@ class C1 { // Invalid, as there is already an exported member. export = C1; ->C1 : C1 +>C1 : import("tests/cases/conformance/externalModules/foo_0") diff --git a/tests/baselines/reference/exportAssignmentWithExports.types b/tests/baselines/reference/exportAssignmentWithExports.types index 5df173d8106e0..e98417d974bca 100644 --- a/tests/baselines/reference/exportAssignmentWithExports.types +++ b/tests/baselines/reference/exportAssignmentWithExports.types @@ -6,5 +6,5 @@ class D { } >D : D export = D; ->D : D +>D : import("tests/cases/compiler/exportAssignmentWithExports") diff --git a/tests/baselines/reference/importTypeGenericTypes.types b/tests/baselines/reference/importTypeGenericTypes.types index 20e811d44d0f0..9a882bd58d48f 100644 --- a/tests/baselines/reference/importTypeGenericTypes.types +++ b/tests/baselines/reference/importTypeGenericTypes.types @@ -55,7 +55,7 @@ export { Bar } === tests/cases/conformance/types/import/usage.ts === export const x: import("./foo")<{x: number}> = { x: 0, y: 0, data: {x: 12} }; ->x : Point<{ x: number; }> +>x : import("tests/cases/conformance/types/import/foo")<{ x: number; }> >x : number >{ x: 0, y: 0, data: {x: 12} } : { x: number; y: number; data: { x: number; }; } >x : number diff --git a/tests/baselines/reference/importTypeInJSDoc.types b/tests/baselines/reference/importTypeInJSDoc.types index ba6bf998a3454..ee28f78f97688 100644 --- a/tests/baselines/reference/importTypeInJSDoc.types +++ b/tests/baselines/reference/importTypeInJSDoc.types @@ -37,20 +37,20 @@ export = MyClass; */ let a = /** @type {Foo} */(/** @type {*} */(undefined)); ->a : MyClass ->(/** @type {*} */(undefined)) : MyClass +>a : import("tests/cases/conformance/types/import/externs") +>(/** @type {*} */(undefined)) : import("tests/cases/conformance/types/import/externs") >(undefined) : any >undefined : undefined a = new Foo({doer: Foo.Bar}); ->a = new Foo({doer: Foo.Bar}) : MyClass ->a : MyClass ->new Foo({doer: Foo.Bar}) : MyClass ->Foo : typeof MyClass +>a = new Foo({doer: Foo.Bar}) : import("tests/cases/conformance/types/import/externs") +>a : import("tests/cases/conformance/types/import/externs") +>new Foo({doer: Foo.Bar}) : import("tests/cases/conformance/types/import/externs") +>Foo : typeof import("tests/cases/conformance/types/import/externs") >{doer: Foo.Bar} : { doer: (x: string, y?: number) => void; } >doer : (x: string, y?: number) => void >Foo.Bar : (x: string, y?: number) => void ->Foo : typeof MyClass +>Foo : typeof import("tests/cases/conformance/types/import/externs") >Bar : (x: string, y?: number) => void const q = /** @type {import("./externs").Bar} */({ doer: q => q }); diff --git a/tests/baselines/reference/importTypeLocal.types b/tests/baselines/reference/importTypeLocal.types index a6d931a1b033b..d106a0d00e7e3 100644 --- a/tests/baselines/reference/importTypeLocal.types +++ b/tests/baselines/reference/importTypeLocal.types @@ -46,7 +46,7 @@ export { Bar } === tests/cases/conformance/types/import/usage.ts === export const x: import("./foo") = { x: 0, y: 0 }; ->x : Point +>x : import("tests/cases/conformance/types/import/foo") >{ x: 0, y: 0 } : { x: number; y: number; } >x : number >0 : 0 diff --git a/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.js b/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.js new file mode 100644 index 0000000000000..a65f487a81a54 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.js @@ -0,0 +1,68 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassExtendsVisibility.ts] //// + +//// [bar.js] +class Bar {} +module.exports = Bar; +//// [cls.js] +const Bar = require("./bar"); +const Strings = { + a: "A", + b: "B" +}; +class Foo extends Bar {} +module.exports = Foo; +module.exports.Strings = Strings; + +//// [bar.js] +var Bar = /** @class */ (function () { + function Bar() { + } + return Bar; +}()); +module.exports = Bar; +//// [cls.js] +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var Bar = require("./bar"); +var Strings = { + a: "A", + b: "B" +}; +var Foo = /** @class */ (function (_super) { + __extends(Foo, _super); + function Foo() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Foo; +}(Bar)); +module.exports = Foo; +module.exports.Strings = Strings; + + +//// [bar.d.ts] +export = Bar; +declare class Bar { +} +//// [cls.d.ts] +export = Foo; +declare const Foo_base: typeof import("./bar"); +declare class Foo extends Foo_base { +} +declare namespace Foo { + export { Strings }; +} +declare namespace Strings { + export const a: string; + export const b: string; +} diff --git a/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.symbols b/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.symbols new file mode 100644 index 0000000000000..cbf083c36f819 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.symbols @@ -0,0 +1,44 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +const Bar = require("./bar"); +>Bar : Symbol(Bar, Decl(cls.js, 0, 5)) +>require : Symbol(require) +>"./bar" : Symbol("tests/cases/conformance/jsdoc/declarations/bar", Decl(bar.js, 0, 0)) + +const Strings = { +>Strings : Symbol(Strings, Decl(cls.js, 1, 5)) + + a: "A", +>a : Symbol(a, Decl(cls.js, 1, 17)) + + b: "B" +>b : Symbol(b, Decl(cls.js, 2, 11)) + +}; +class Foo extends Bar {} +>Foo : Symbol(Foo, Decl(cls.js, 4, 2)) +>Bar : Symbol(Bar, Decl(cls.js, 0, 5)) + +module.exports = Foo; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) +>module : Symbol(export=, Decl(cls.js, 5, 24)) +>exports : Symbol(export=, Decl(cls.js, 5, 24)) +>Foo : Symbol(Foo, Decl(cls.js, 4, 2)) + +module.exports.Strings = Strings; +>module.exports.Strings : Symbol(Strings) +>module.exports : Symbol(Strings, Decl(cls.js, 6, 21)) +>module : Symbol(module, Decl(cls.js, 5, 24)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) +>Strings : Symbol(Strings, Decl(cls.js, 6, 21)) +>Strings : Symbol(Strings, Decl(cls.js, 1, 5)) + +=== tests/cases/conformance/jsdoc/declarations/bar.js === +class Bar {} +>Bar : Symbol(Bar, Decl(bar.js, 0, 0)) + +module.exports = Bar; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/bar", Decl(bar.js, 0, 0)) +>module : Symbol(export=, Decl(bar.js, 0, 12)) +>exports : Symbol(export=, Decl(bar.js, 0, 12)) +>Bar : Symbol(Bar, Decl(bar.js, 0, 0)) + diff --git a/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.types b/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.types new file mode 100644 index 0000000000000..fe35b959cf04e --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassExtendsVisibility.types @@ -0,0 +1,51 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +const Bar = require("./bar"); +>Bar : typeof import("tests/cases/conformance/jsdoc/declarations/bar") +>require("./bar") : typeof import("tests/cases/conformance/jsdoc/declarations/bar") +>require : any +>"./bar" : "./bar" + +const Strings = { +>Strings : { a: string; b: string; } +>{ a: "A", b: "B"} : { a: string; b: string; } + + a: "A", +>a : string +>"A" : "A" + + b: "B" +>b : string +>"B" : "B" + +}; +class Foo extends Bar {} +>Foo : Foo +>Bar : import("tests/cases/conformance/jsdoc/declarations/bar") + +module.exports = Foo; +>module.exports = Foo : typeof Foo +>module.exports : typeof Foo +>module : { "tests/cases/conformance/jsdoc/declarations/cls": typeof Foo; } +>exports : typeof Foo +>Foo : typeof Foo + +module.exports.Strings = Strings; +>module.exports.Strings = Strings : { a: string; b: string; } +>module.exports.Strings : { a: string; b: string; } +>module.exports : typeof Foo +>module : { "tests/cases/conformance/jsdoc/declarations/cls": typeof Foo; } +>exports : typeof Foo +>Strings : { a: string; b: string; } +>Strings : { a: string; b: string; } + +=== tests/cases/conformance/jsdoc/declarations/bar.js === +class Bar {} +>Bar : Bar + +module.exports = Bar; +>module.exports = Bar : typeof Bar +>module.exports : typeof Bar +>module : { "tests/cases/conformance/jsdoc/declarations/bar": typeof Bar; } +>exports : typeof Bar +>Bar : typeof Bar + diff --git a/tests/baselines/reference/jsDeclarationsClasses.js b/tests/baselines/reference/jsDeclarationsClasses.js new file mode 100644 index 0000000000000..d94e8690a3c58 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClasses.js @@ -0,0 +1,591 @@ +//// [index.js] +export class A {} + +export class B { + static cat = "cat"; +} + +export class C { + static Cls = class {} +} + +export class D { + /** + * @param {number} a + * @param {number} b + */ + constructor(a, b) {} +} + +/** + * @template T,U + */ +export class E { + /** + * @type {T & U} + */ + field; + + // @readonly is currently unsupported, it seems - included here just in case that changes + /** + * @type {T & U} + * @readonly + */ + readonlyField; + + initializedField = 12; + + /** + * @return {U} + */ + get f1() { return /** @type {*} */(null); } + + /** + * @param {U} _p + */ + set f1(_p) {} + + /** + * @return {U} + */ + get f2() { return /** @type {*} */(null); } + + /** + * @param {U} _p + */ + set f3(_p) {} + + /** + * @param {T} a + * @param {U} b + */ + constructor(a, b) {} + + + /** + * @type {string} + */ + static staticField; + + // @readonly is currently unsupported, it seems - included here just in case that changes + /** + * @type {string} + * @readonly + */ + static staticReadonlyField; + + static staticInitializedField = 12; + + /** + * @return {string} + */ + static get s1() { return ""; } + + /** + * @param {string} _p + */ + static set s1(_p) {} + + /** + * @return {string} + */ + static get s2() { return ""; } + + /** + * @param {string} _p + */ + static set s3(_p) {} +} + +/** + * @template T,U + */ +export class F { + /** + * @type {T & U} + */ + field; + /** + * @param {T} a + * @param {U} b + */ + constructor(a, b) {} + + /** + * @template A,B + * @param {A} a + * @param {B} b + */ + static create(a, b) { return new F(a, b); } +} + +class G {} + +export { G }; + +class HH {} + +export { HH as H }; + +export class I {} +export { I as II }; + +export { J as JJ }; +export class J {} + + +export class K { + constructor() { + this.p1 = 12; + this.p2 = "ok"; + } + + method() { + return this.p1; + } +} + +export class L extends K {} + +export class M extends null { + constructor() { + this.prop = 12; + } +} + + +/** + * @template T + */ +export class N extends L { + /** + * @param {T} param + */ + constructor(param) { + super(); + this.another = param; + } +} + +/** + * @template U + * @extends {N} + */ +export class O extends N { + /** + * @param {U} param + */ + constructor(param) { + super(param); + this.another2 = param; + } +} + +var x = /** @type {*} */(null); + +export class VariableBase extends x {} + +export class HasStatics { + static staticMethod() {} +} + +export class ExtendsStatics extends HasStatics { + static also() {} +} + + +//// [index.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var A = /** @class */ (function () { + function A() { + } + return A; +}()); +exports.A = A; +var B = /** @class */ (function () { + function B() { + } + B.cat = "cat"; + return B; +}()); +exports.B = B; +var C = /** @class */ (function () { + function C() { + } + C.Cls = /** @class */ (function () { + function class_1() { + } + return class_1; + }()); + return C; +}()); +exports.C = C; +var D = /** @class */ (function () { + /** + * @param {number} a + * @param {number} b + */ + function D(a, b) { + } + return D; +}()); +exports.D = D; +/** + * @template T,U + */ +var E = /** @class */ (function () { + /** + * @param {T} a + * @param {U} b + */ + function E(a, b) { + this.initializedField = 12; + } + Object.defineProperty(E.prototype, "f1", { + /** + * @return {U} + */ + get: function () { return /** @type {*} */ (null); }, + /** + * @param {U} _p + */ + set: function (_p) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(E.prototype, "f2", { + /** + * @return {U} + */ + get: function () { return /** @type {*} */ (null); }, + enumerable: true, + configurable: true + }); + Object.defineProperty(E.prototype, "f3", { + /** + * @param {U} _p + */ + set: function (_p) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(E, "s1", { + /** + * @return {string} + */ + get: function () { return ""; }, + /** + * @param {string} _p + */ + set: function (_p) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(E, "s2", { + /** + * @return {string} + */ + get: function () { return ""; }, + enumerable: true, + configurable: true + }); + Object.defineProperty(E, "s3", { + /** + * @param {string} _p + */ + set: function (_p) { }, + enumerable: true, + configurable: true + }); + E.staticInitializedField = 12; + return E; +}()); +exports.E = E; +/** + * @template T,U + */ +var F = /** @class */ (function () { + /** + * @param {T} a + * @param {U} b + */ + function F(a, b) { + } + /** + * @template A,B + * @param {A} a + * @param {B} b + */ + F.create = function (a, b) { return new F(a, b); }; + return F; +}()); +exports.F = F; +var G = /** @class */ (function () { + function G() { + } + return G; +}()); +exports.G = G; +var HH = /** @class */ (function () { + function HH() { + } + return HH; +}()); +exports.H = HH; +var I = /** @class */ (function () { + function I() { + } + return I; +}()); +exports.I = I; +exports.II = I; +var J = /** @class */ (function () { + function J() { + } + return J; +}()); +exports.JJ = J; +exports.J = J; +var K = /** @class */ (function () { + function K() { + this.p1 = 12; + this.p2 = "ok"; + } + K.prototype.method = function () { + return this.p1; + }; + return K; +}()); +exports.K = K; +var L = /** @class */ (function (_super) { + __extends(L, _super); + function L() { + return _super !== null && _super.apply(this, arguments) || this; + } + return L; +}(K)); +exports.L = L; +var M = /** @class */ (function (_super) { + __extends(M, _super); + function M() { + _this.prop = 12; + } + return M; +}(null)); +exports.M = M; +/** + * @template T + */ +var N = /** @class */ (function (_super) { + __extends(N, _super); + /** + * @param {T} param + */ + function N(param) { + var _this = _super.call(this) || this; + _this.another = param; + return _this; + } + return N; +}(L)); +exports.N = N; +/** + * @template U + * @extends {N} + */ +var O = /** @class */ (function (_super) { + __extends(O, _super); + /** + * @param {U} param + */ + function O(param) { + var _this = _super.call(this, param) || this; + _this.another2 = param; + return _this; + } + return O; +}(N)); +exports.O = O; +var x = /** @type {*} */ (null); +var VariableBase = /** @class */ (function (_super) { + __extends(VariableBase, _super); + function VariableBase() { + return _super !== null && _super.apply(this, arguments) || this; + } + return VariableBase; +}(x)); +exports.VariableBase = VariableBase; +var HasStatics = /** @class */ (function () { + function HasStatics() { + } + HasStatics.staticMethod = function () { }; + return HasStatics; +}()); +exports.HasStatics = HasStatics; +var ExtendsStatics = /** @class */ (function (_super) { + __extends(ExtendsStatics, _super); + function ExtendsStatics() { + return _super !== null && _super.apply(this, arguments) || this; + } + ExtendsStatics.also = function () { }; + return ExtendsStatics; +}(HasStatics)); +exports.ExtendsStatics = ExtendsStatics; + + +//// [index.d.ts] +export class A { +} +export class B { + static cat: string; +} +export class C { + static Cls: { + new (): {}; + }; +} +export class D { + /** + * @param {number} a + * @param {number} b + */ + constructor(a: number, b: number); +} +/** + * @template T,U + */ +export class E { + /** + * @type {string} + */ + static staticField: string; + /** + * @type {string} + * @readonly + */ + static staticReadonlyField: string; + static staticInitializedField: number; + /** + * @return {string} + */ + static s1: string; + /** + * @return {string} + */ + static readonly s2: string; + /** + * @param {string} _p + */ + static s3: string; + /** + * @param {T} a + * @param {U} b + */ + constructor(a: T, b: U); + /** + * @type {T & U} + */ + field: T & U; + /** + * @type {T & U} + * @readonly + */ + readonlyField: T & U; + initializedField: number; + /** + * @return {U} + */ + f1: U; + /** + * @return {U} + */ + readonly f2: U; + /** + * @param {U} _p + */ + f3: U; +} +/** + * @template T,U + */ +export class F { + /** + * @template A,B + * @param {A} a + * @param {B} b + */ + static create(a: A_1, b: B_1): F; + /** + * @param {T} a + * @param {U} b + */ + constructor(a: T, b: U); + /** + * @type {T & U} + */ + field: T & U; +} +export class I { +} +export class J { +} +export class K { + p1: number; + p2: string; + method(): number; +} +export class L extends K { +} +export class M { + prop: number; +} +/** + * @template T + */ +export class N extends L { + /** + * @param {T} param + */ + constructor(param: T); + another: T; +} +/** + * @template U + * @extends {N} + */ +export class O extends N { + /** + * @param {U} param + */ + constructor(param: U); + another2: U; +} +declare const VariableBase_base: any; +export class VariableBase extends VariableBase_base { + [x: string]: any; +} +export class HasStatics { + static staticMethod(): void; +} +export class ExtendsStatics extends HasStatics { + static also(): void; +} +export class G { +} +declare class HH { +} +export { HH as H, I as II, J as JJ }; diff --git a/tests/baselines/reference/jsDeclarationsClasses.symbols b/tests/baselines/reference/jsDeclarationsClasses.symbols new file mode 100644 index 0000000000000..dd92edbd4e65c --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClasses.symbols @@ -0,0 +1,307 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +export class A {} +>A : Symbol(A, Decl(index.js, 0, 0)) + +export class B { +>B : Symbol(B, Decl(index.js, 0, 17)) + + static cat = "cat"; +>cat : Symbol(B.cat, Decl(index.js, 2, 16)) +} + +export class C { +>C : Symbol(C, Decl(index.js, 4, 1)) + + static Cls = class {} +>Cls : Symbol(C.Cls, Decl(index.js, 6, 16)) +} + +export class D { +>D : Symbol(D, Decl(index.js, 8, 1)) + + /** + * @param {number} a + * @param {number} b + */ + constructor(a, b) {} +>a : Symbol(a, Decl(index.js, 15, 16)) +>b : Symbol(b, Decl(index.js, 15, 18)) +} + +/** + * @template T,U + */ +export class E { +>E : Symbol(E, Decl(index.js, 16, 1)) + + /** + * @type {T & U} + */ + field; +>field : Symbol(E.field, Decl(index.js, 21, 16)) + + // @readonly is currently unsupported, it seems - included here just in case that changes + /** + * @type {T & U} + * @readonly + */ + readonlyField; +>readonlyField : Symbol(E.readonlyField, Decl(index.js, 25, 10)) + + initializedField = 12; +>initializedField : Symbol(E.initializedField, Decl(index.js, 32, 18)) + + /** + * @return {U} + */ + get f1() { return /** @type {*} */(null); } +>f1 : Symbol(E.f1, Decl(index.js, 34, 26), Decl(index.js, 39, 47)) + + /** + * @param {U} _p + */ + set f1(_p) {} +>f1 : Symbol(E.f1, Decl(index.js, 34, 26), Decl(index.js, 39, 47)) +>_p : Symbol(_p, Decl(index.js, 44, 11)) + + /** + * @return {U} + */ + get f2() { return /** @type {*} */(null); } +>f2 : Symbol(E.f2, Decl(index.js, 44, 17)) + + /** + * @param {U} _p + */ + set f3(_p) {} +>f3 : Symbol(E.f3, Decl(index.js, 49, 47)) +>_p : Symbol(_p, Decl(index.js, 54, 11)) + + /** + * @param {T} a + * @param {U} b + */ + constructor(a, b) {} +>a : Symbol(a, Decl(index.js, 60, 16)) +>b : Symbol(b, Decl(index.js, 60, 18)) + + + /** + * @type {string} + */ + static staticField; +>staticField : Symbol(E.staticField, Decl(index.js, 60, 24)) + + // @readonly is currently unsupported, it seems - included here just in case that changes + /** + * @type {string} + * @readonly + */ + static staticReadonlyField; +>staticReadonlyField : Symbol(E.staticReadonlyField, Decl(index.js, 66, 23)) + + static staticInitializedField = 12; +>staticInitializedField : Symbol(E.staticInitializedField, Decl(index.js, 73, 31)) + + /** + * @return {string} + */ + static get s1() { return ""; } +>s1 : Symbol(E.s1, Decl(index.js, 75, 39), Decl(index.js, 80, 34)) + + /** + * @param {string} _p + */ + static set s1(_p) {} +>s1 : Symbol(E.s1, Decl(index.js, 75, 39), Decl(index.js, 80, 34)) +>_p : Symbol(_p, Decl(index.js, 85, 18)) + + /** + * @return {string} + */ + static get s2() { return ""; } +>s2 : Symbol(E.s2, Decl(index.js, 85, 24)) + + /** + * @param {string} _p + */ + static set s3(_p) {} +>s3 : Symbol(E.s3, Decl(index.js, 90, 34)) +>_p : Symbol(_p, Decl(index.js, 95, 18)) +} + +/** + * @template T,U + */ +export class F { +>F : Symbol(F, Decl(index.js, 96, 1)) + + /** + * @type {T & U} + */ + field; +>field : Symbol(F.field, Decl(index.js, 101, 16)) + + /** + * @param {T} a + * @param {U} b + */ + constructor(a, b) {} +>a : Symbol(a, Decl(index.js, 110, 16)) +>b : Symbol(b, Decl(index.js, 110, 18)) + + /** + * @template A,B + * @param {A} a + * @param {B} b + */ + static create(a, b) { return new F(a, b); } +>create : Symbol(F.create, Decl(index.js, 110, 24)) +>a : Symbol(a, Decl(index.js, 117, 18)) +>b : Symbol(b, Decl(index.js, 117, 20)) +>F : Symbol(F, Decl(index.js, 96, 1)) +>a : Symbol(a, Decl(index.js, 117, 18)) +>b : Symbol(b, Decl(index.js, 117, 20)) +} + +class G {} +>G : Symbol(G, Decl(index.js, 118, 1)) + +export { G }; +>G : Symbol(G, Decl(index.js, 122, 8)) + +class HH {} +>HH : Symbol(HH, Decl(index.js, 122, 13)) + +export { HH as H }; +>HH : Symbol(HH, Decl(index.js, 122, 13)) +>H : Symbol(H, Decl(index.js, 126, 8)) + +export class I {} +>I : Symbol(I, Decl(index.js, 126, 19)) + +export { I as II }; +>I : Symbol(I, Decl(index.js, 126, 19)) +>II : Symbol(II, Decl(index.js, 129, 8)) + +export { J as JJ }; +>J : Symbol(J, Decl(index.js, 131, 19)) +>JJ : Symbol(JJ, Decl(index.js, 131, 8)) + +export class J {} +>J : Symbol(J, Decl(index.js, 131, 19)) + + +export class K { +>K : Symbol(K, Decl(index.js, 132, 17)) + + constructor() { + this.p1 = 12; +>this.p1 : Symbol(K.p1, Decl(index.js, 136, 19)) +>this : Symbol(K, Decl(index.js, 132, 17)) +>p1 : Symbol(K.p1, Decl(index.js, 136, 19)) + + this.p2 = "ok"; +>this.p2 : Symbol(K.p2, Decl(index.js, 137, 21)) +>this : Symbol(K, Decl(index.js, 132, 17)) +>p2 : Symbol(K.p2, Decl(index.js, 137, 21)) + } + + method() { +>method : Symbol(K.method, Decl(index.js, 139, 5)) + + return this.p1; +>this.p1 : Symbol(K.p1, Decl(index.js, 136, 19)) +>this : Symbol(K, Decl(index.js, 132, 17)) +>p1 : Symbol(K.p1, Decl(index.js, 136, 19)) + } +} + +export class L extends K {} +>L : Symbol(L, Decl(index.js, 144, 1)) +>K : Symbol(K, Decl(index.js, 132, 17)) + +export class M extends null { +>M : Symbol(M, Decl(index.js, 146, 27)) + + constructor() { + this.prop = 12; +>this.prop : Symbol(M.prop, Decl(index.js, 149, 19)) +>this : Symbol(M, Decl(index.js, 146, 27)) +>prop : Symbol(M.prop, Decl(index.js, 149, 19)) + } +} + + +/** + * @template T + */ +export class N extends L { +>N : Symbol(N, Decl(index.js, 152, 1)) +>L : Symbol(L, Decl(index.js, 144, 1)) + + /** + * @param {T} param + */ + constructor(param) { +>param : Symbol(param, Decl(index.js, 162, 16)) + + super(); +>super : Symbol(L, Decl(index.js, 144, 1)) + + this.another = param; +>this.another : Symbol(N.another, Decl(index.js, 163, 16)) +>this : Symbol(N, Decl(index.js, 152, 1)) +>another : Symbol(N.another, Decl(index.js, 163, 16)) +>param : Symbol(param, Decl(index.js, 162, 16)) + } +} + +/** + * @template U + * @extends {N} + */ +export class O extends N { +>O : Symbol(O, Decl(index.js, 166, 1)) +>N : Symbol(N, Decl(index.js, 152, 1)) + + /** + * @param {U} param + */ + constructor(param) { +>param : Symbol(param, Decl(index.js, 176, 16)) + + super(param); +>super : Symbol(N, Decl(index.js, 152, 1)) +>param : Symbol(param, Decl(index.js, 176, 16)) + + this.another2 = param; +>this.another2 : Symbol(O.another2, Decl(index.js, 177, 21)) +>this : Symbol(O, Decl(index.js, 166, 1)) +>another2 : Symbol(O.another2, Decl(index.js, 177, 21)) +>param : Symbol(param, Decl(index.js, 176, 16)) + } +} + +var x = /** @type {*} */(null); +>x : Symbol(x, Decl(index.js, 182, 3)) + +export class VariableBase extends x {} +>VariableBase : Symbol(VariableBase, Decl(index.js, 182, 31)) +>x : Symbol(x, Decl(index.js, 182, 3)) + +export class HasStatics { +>HasStatics : Symbol(HasStatics, Decl(index.js, 184, 38)) + + static staticMethod() {} +>staticMethod : Symbol(HasStatics.staticMethod, Decl(index.js, 186, 25)) +} + +export class ExtendsStatics extends HasStatics { +>ExtendsStatics : Symbol(ExtendsStatics, Decl(index.js, 188, 1)) +>HasStatics : Symbol(HasStatics, Decl(index.js, 184, 38)) + + static also() {} +>also : Symbol(ExtendsStatics.also, Decl(index.js, 190, 48)) +} + diff --git a/tests/baselines/reference/jsDeclarationsClasses.types b/tests/baselines/reference/jsDeclarationsClasses.types new file mode 100644 index 0000000000000..bbcea688c2691 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClasses.types @@ -0,0 +1,331 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +export class A {} +>A : A + +export class B { +>B : B + + static cat = "cat"; +>cat : string +>"cat" : "cat" +} + +export class C { +>C : C + + static Cls = class {} +>Cls : typeof (Anonymous class) +>class {} : typeof (Anonymous class) +} + +export class D { +>D : D + + /** + * @param {number} a + * @param {number} b + */ + constructor(a, b) {} +>a : number +>b : number +} + +/** + * @template T,U + */ +export class E { +>E : E + + /** + * @type {T & U} + */ + field; +>field : T & U + + // @readonly is currently unsupported, it seems - included here just in case that changes + /** + * @type {T & U} + * @readonly + */ + readonlyField; +>readonlyField : T & U + + initializedField = 12; +>initializedField : number +>12 : 12 + + /** + * @return {U} + */ + get f1() { return /** @type {*} */(null); } +>f1 : U +>(null) : any +>null : null + + /** + * @param {U} _p + */ + set f1(_p) {} +>f1 : U +>_p : U + + /** + * @return {U} + */ + get f2() { return /** @type {*} */(null); } +>f2 : U +>(null) : any +>null : null + + /** + * @param {U} _p + */ + set f3(_p) {} +>f3 : U +>_p : U + + /** + * @param {T} a + * @param {U} b + */ + constructor(a, b) {} +>a : T +>b : U + + + /** + * @type {string} + */ + static staticField; +>staticField : string + + // @readonly is currently unsupported, it seems - included here just in case that changes + /** + * @type {string} + * @readonly + */ + static staticReadonlyField; +>staticReadonlyField : string + + static staticInitializedField = 12; +>staticInitializedField : number +>12 : 12 + + /** + * @return {string} + */ + static get s1() { return ""; } +>s1 : string +>"" : "" + + /** + * @param {string} _p + */ + static set s1(_p) {} +>s1 : string +>_p : string + + /** + * @return {string} + */ + static get s2() { return ""; } +>s2 : string +>"" : "" + + /** + * @param {string} _p + */ + static set s3(_p) {} +>s3 : string +>_p : string +} + +/** + * @template T,U + */ +export class F { +>F : F + + /** + * @type {T & U} + */ + field; +>field : T & U + + /** + * @param {T} a + * @param {U} b + */ + constructor(a, b) {} +>a : T +>b : U + + /** + * @template A,B + * @param {A} a + * @param {B} b + */ + static create(a, b) { return new F(a, b); } +>create : (a: A, b: B) => F +>a : A +>b : B +>new F(a, b) : F +>F : typeof F +>a : A +>b : B +} + +class G {} +>G : G + +export { G }; +>G : typeof G + +class HH {} +>HH : HH + +export { HH as H }; +>HH : typeof HH +>H : typeof HH + +export class I {} +>I : I + +export { I as II }; +>I : typeof I +>II : typeof I + +export { J as JJ }; +>J : typeof J +>JJ : typeof J + +export class J {} +>J : J + + +export class K { +>K : K + + constructor() { + this.p1 = 12; +>this.p1 = 12 : 12 +>this.p1 : number +>this : this +>p1 : number +>12 : 12 + + this.p2 = "ok"; +>this.p2 = "ok" : "ok" +>this.p2 : string +>this : this +>p2 : string +>"ok" : "ok" + } + + method() { +>method : () => number + + return this.p1; +>this.p1 : number +>this : this +>p1 : number + } +} + +export class L extends K {} +>L : L +>K : K + +export class M extends null { +>M : M +>null : null + + constructor() { + this.prop = 12; +>this.prop = 12 : 12 +>this.prop : number +>this : this +>prop : number +>12 : 12 + } +} + + +/** + * @template T + */ +export class N extends L { +>N : N +>L : L + + /** + * @param {T} param + */ + constructor(param) { +>param : T + + super(); +>super() : void +>super : typeof L + + this.another = param; +>this.another = param : T +>this.another : T +>this : this +>another : T +>param : T + } +} + +/** + * @template U + * @extends {N} + */ +export class O extends N { +>O : O +>N : N + + /** + * @param {U} param + */ + constructor(param) { +>param : U + + super(param); +>super(param) : void +>super : typeof N +>param : U + + this.another2 = param; +>this.another2 = param : U +>this.another2 : U +>this : this +>another2 : U +>param : U + } +} + +var x = /** @type {*} */(null); +>x : any +>(null) : any +>null : null + +export class VariableBase extends x {} +>VariableBase : VariableBase +>x : any + +export class HasStatics { +>HasStatics : HasStatics + + static staticMethod() {} +>staticMethod : () => void +} + +export class ExtendsStatics extends HasStatics { +>ExtendsStatics : ExtendsStatics +>HasStatics : HasStatics + + static also() {} +>also : () => void +} + diff --git a/tests/baselines/reference/jsDeclarationsClassesErr.errors.txt b/tests/baselines/reference/jsDeclarationsClassesErr.errors.txt new file mode 100644 index 0000000000000..ef78bf109c843 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassesErr.errors.txt @@ -0,0 +1,136 @@ +tests/cases/conformance/jsdoc/declarations/index.js(4,16): error TS8004: 'type parameter declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(5,12): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(8,16): error TS8004: 'type parameter declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(8,29): error TS8011: 'type arguments' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(9,12): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(13,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(19,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(23,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(27,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(28,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(32,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(39,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(43,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(47,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(48,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(52,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(53,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(59,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(63,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(67,11): error TS8010: 'types' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(68,11): error TS8010: 'types' can only be used in a .ts file. + + +==== tests/cases/conformance/jsdoc/declarations/index.js (21 errors) ==== + // Pretty much all of this should be an error, (since index signatures and generics are forbidden in js), + // but we should be able to synthesize declarations from the symbols regardless + + export class M { + ~ +!!! error TS8004: 'type parameter declarations' can only be used in a .ts file. + field: T; + ~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class N extends M { + ~ +!!! error TS8004: 'type parameter declarations' can only be used in a .ts file. + ~ +!!! error TS8011: 'type arguments' can only be used in a .ts file. + other: U; + ~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class O { + [idx: string]: string; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class P extends O {} + + export class Q extends O { + [idx: string]: "ok"; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class R extends O { + [idx: number]: "ok"; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class S extends O { + [idx: string]: "ok"; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + [idx: number]: never; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class T { + [idx: number]: string; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class U extends T {} + + + export class V extends T { + [idx: string]: string; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class W extends T { + [idx: number]: "ok"; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class X extends T { + [idx: string]: string; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + [idx: number]: "ok"; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class Y { + [idx: string]: {x: number}; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + [idx: number]: {x: number, y: number}; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class Z extends Y {} + + export class AA extends Y { + [idx: string]: {x: number, y: number}; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class BB extends Y { + [idx: number]: {x: 0, y: 0}; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + + export class CC extends Y { + [idx: string]: {x: number, y: number}; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + [idx: number]: {x: 0, y: 0}; + ~~~~~~ +!!! error TS8010: 'types' can only be used in a .ts file. + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsClassesErr.js b/tests/baselines/reference/jsDeclarationsClassesErr.js new file mode 100644 index 0000000000000..0241e9693c673 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassesErr.js @@ -0,0 +1,290 @@ +//// [index.js] +// Pretty much all of this should be an error, (since index signatures and generics are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export class M { + field: T; +} + +export class N extends M { + other: U; +} + +export class O { + [idx: string]: string; +} + +export class P extends O {} + +export class Q extends O { + [idx: string]: "ok"; +} + +export class R extends O { + [idx: number]: "ok"; +} + +export class S extends O { + [idx: string]: "ok"; + [idx: number]: never; +} + +export class T { + [idx: number]: string; +} + +export class U extends T {} + + +export class V extends T { + [idx: string]: string; +} + +export class W extends T { + [idx: number]: "ok"; +} + +export class X extends T { + [idx: string]: string; + [idx: number]: "ok"; +} + +export class Y { + [idx: string]: {x: number}; + [idx: number]: {x: number, y: number}; +} + +export class Z extends Y {} + +export class AA extends Y { + [idx: string]: {x: number, y: number}; +} + +export class BB extends Y { + [idx: number]: {x: 0, y: 0}; +} + +export class CC extends Y { + [idx: string]: {x: number, y: number}; + [idx: number]: {x: 0, y: 0}; +} + + +//// [index.js] +"use strict"; +// Pretty much all of this should be an error, (since index signatures and generics are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var M = /** @class */ (function () { + function M() { + } + return M; +}()); +exports.M = M; +var N = /** @class */ (function (_super) { + __extends(N, _super); + function N() { + return _super !== null && _super.apply(this, arguments) || this; + } + return N; +}(M)); +exports.N = N; +var O = /** @class */ (function () { + function O() { + } + return O; +}()); +exports.O = O; +var P = /** @class */ (function (_super) { + __extends(P, _super); + function P() { + return _super !== null && _super.apply(this, arguments) || this; + } + return P; +}(O)); +exports.P = P; +var Q = /** @class */ (function (_super) { + __extends(Q, _super); + function Q() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Q; +}(O)); +exports.Q = Q; +var R = /** @class */ (function (_super) { + __extends(R, _super); + function R() { + return _super !== null && _super.apply(this, arguments) || this; + } + return R; +}(O)); +exports.R = R; +var S = /** @class */ (function (_super) { + __extends(S, _super); + function S() { + return _super !== null && _super.apply(this, arguments) || this; + } + return S; +}(O)); +exports.S = S; +var T = /** @class */ (function () { + function T() { + } + return T; +}()); +exports.T = T; +var U = /** @class */ (function (_super) { + __extends(U, _super); + function U() { + return _super !== null && _super.apply(this, arguments) || this; + } + return U; +}(T)); +exports.U = U; +var V = /** @class */ (function (_super) { + __extends(V, _super); + function V() { + return _super !== null && _super.apply(this, arguments) || this; + } + return V; +}(T)); +exports.V = V; +var W = /** @class */ (function (_super) { + __extends(W, _super); + function W() { + return _super !== null && _super.apply(this, arguments) || this; + } + return W; +}(T)); +exports.W = W; +var X = /** @class */ (function (_super) { + __extends(X, _super); + function X() { + return _super !== null && _super.apply(this, arguments) || this; + } + return X; +}(T)); +exports.X = X; +var Y = /** @class */ (function () { + function Y() { + } + return Y; +}()); +exports.Y = Y; +var Z = /** @class */ (function (_super) { + __extends(Z, _super); + function Z() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Z; +}(Y)); +exports.Z = Z; +var AA = /** @class */ (function (_super) { + __extends(AA, _super); + function AA() { + return _super !== null && _super.apply(this, arguments) || this; + } + return AA; +}(Y)); +exports.AA = AA; +var BB = /** @class */ (function (_super) { + __extends(BB, _super); + function BB() { + return _super !== null && _super.apply(this, arguments) || this; + } + return BB; +}(Y)); +exports.BB = BB; +var CC = /** @class */ (function (_super) { + __extends(CC, _super); + function CC() { + return _super !== null && _super.apply(this, arguments) || this; + } + return CC; +}(Y)); +exports.CC = CC; + + +//// [index.d.ts] +export class M { + field: T_1; +} +export class N extends M { + other: U_1; +} +export class O { + [idx: string]: string; +} +export class P extends O { +} +export class Q extends O { + [idx: string]: "ok"; +} +export class R extends O { + [idx: number]: "ok"; +} +export class S extends O { + [idx: string]: "ok"; + [idx: number]: never; +} +export class T { + [idx: number]: string; +} +export class U extends T { +} +export class V extends T { + [idx: string]: string; +} +export class W extends T { + [idx: number]: "ok"; +} +export class X extends T { + [idx: string]: string; + [idx: number]: "ok"; +} +export class Y { + [idx: string]: { + x: number; + }; + [idx: number]: { + x: number; + y: number; + }; +} +export class Z extends Y { +} +export class AA extends Y { + [idx: string]: { + x: number; + y: number; + }; +} +export class BB extends Y { + [idx: number]: { + x: 0; + y: 0; + }; +} +export class CC extends Y { + [idx: string]: { + x: number; + y: number; + }; + [idx: number]: { + x: 0; + y: 0; + }; +} diff --git a/tests/baselines/reference/jsDeclarationsClassesErr.symbols b/tests/baselines/reference/jsDeclarationsClassesErr.symbols new file mode 100644 index 0000000000000..3e0d026a83f66 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassesErr.symbols @@ -0,0 +1,153 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// Pretty much all of this should be an error, (since index signatures and generics are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export class M { +>M : Symbol(M, Decl(index.js, 0, 0)) +>T : Symbol(T, Decl(index.js, 3, 15)) + + field: T; +>field : Symbol(M.field, Decl(index.js, 3, 19)) +>T : Symbol(T, Decl(index.js, 3, 15)) +} + +export class N extends M { +>N : Symbol(N, Decl(index.js, 5, 1)) +>U : Symbol(U, Decl(index.js, 7, 15)) +>M : Symbol(M, Decl(index.js, 0, 0)) +>U : Symbol(U, Decl(index.js, 7, 15)) + + other: U; +>other : Symbol(N.other, Decl(index.js, 7, 32)) +>U : Symbol(U, Decl(index.js, 7, 15)) +} + +export class O { +>O : Symbol(O, Decl(index.js, 9, 1)) + + [idx: string]: string; +>idx : Symbol(idx, Decl(index.js, 12, 5)) +} + +export class P extends O {} +>P : Symbol(P, Decl(index.js, 13, 1)) +>O : Symbol(O, Decl(index.js, 9, 1)) + +export class Q extends O { +>Q : Symbol(Q, Decl(index.js, 15, 27)) +>O : Symbol(O, Decl(index.js, 9, 1)) + + [idx: string]: "ok"; +>idx : Symbol(idx, Decl(index.js, 18, 5)) +} + +export class R extends O { +>R : Symbol(R, Decl(index.js, 19, 1)) +>O : Symbol(O, Decl(index.js, 9, 1)) + + [idx: number]: "ok"; +>idx : Symbol(idx, Decl(index.js, 22, 5)) +} + +export class S extends O { +>S : Symbol(S, Decl(index.js, 23, 1)) +>O : Symbol(O, Decl(index.js, 9, 1)) + + [idx: string]: "ok"; +>idx : Symbol(idx, Decl(index.js, 26, 5)) + + [idx: number]: never; +>idx : Symbol(idx, Decl(index.js, 27, 5)) +} + +export class T { +>T : Symbol(T, Decl(index.js, 28, 1)) + + [idx: number]: string; +>idx : Symbol(idx, Decl(index.js, 31, 5)) +} + +export class U extends T {} +>U : Symbol(U, Decl(index.js, 32, 1)) +>T : Symbol(T, Decl(index.js, 28, 1)) + + +export class V extends T { +>V : Symbol(V, Decl(index.js, 34, 27)) +>T : Symbol(T, Decl(index.js, 28, 1)) + + [idx: string]: string; +>idx : Symbol(idx, Decl(index.js, 38, 5)) +} + +export class W extends T { +>W : Symbol(W, Decl(index.js, 39, 1)) +>T : Symbol(T, Decl(index.js, 28, 1)) + + [idx: number]: "ok"; +>idx : Symbol(idx, Decl(index.js, 42, 5)) +} + +export class X extends T { +>X : Symbol(X, Decl(index.js, 43, 1)) +>T : Symbol(T, Decl(index.js, 28, 1)) + + [idx: string]: string; +>idx : Symbol(idx, Decl(index.js, 46, 5)) + + [idx: number]: "ok"; +>idx : Symbol(idx, Decl(index.js, 47, 5)) +} + +export class Y { +>Y : Symbol(Y, Decl(index.js, 48, 1)) + + [idx: string]: {x: number}; +>idx : Symbol(idx, Decl(index.js, 51, 5)) +>x : Symbol(x, Decl(index.js, 51, 20)) + + [idx: number]: {x: number, y: number}; +>idx : Symbol(idx, Decl(index.js, 52, 5)) +>x : Symbol(x, Decl(index.js, 52, 20)) +>y : Symbol(y, Decl(index.js, 52, 30)) +} + +export class Z extends Y {} +>Z : Symbol(Z, Decl(index.js, 53, 1)) +>Y : Symbol(Y, Decl(index.js, 48, 1)) + +export class AA extends Y { +>AA : Symbol(AA, Decl(index.js, 55, 27)) +>Y : Symbol(Y, Decl(index.js, 48, 1)) + + [idx: string]: {x: number, y: number}; +>idx : Symbol(idx, Decl(index.js, 58, 5)) +>x : Symbol(x, Decl(index.js, 58, 20)) +>y : Symbol(y, Decl(index.js, 58, 30)) +} + +export class BB extends Y { +>BB : Symbol(BB, Decl(index.js, 59, 1)) +>Y : Symbol(Y, Decl(index.js, 48, 1)) + + [idx: number]: {x: 0, y: 0}; +>idx : Symbol(idx, Decl(index.js, 62, 5)) +>x : Symbol(x, Decl(index.js, 62, 20)) +>y : Symbol(y, Decl(index.js, 62, 25)) +} + +export class CC extends Y { +>CC : Symbol(CC, Decl(index.js, 63, 1)) +>Y : Symbol(Y, Decl(index.js, 48, 1)) + + [idx: string]: {x: number, y: number}; +>idx : Symbol(idx, Decl(index.js, 66, 5)) +>x : Symbol(x, Decl(index.js, 66, 20)) +>y : Symbol(y, Decl(index.js, 66, 30)) + + [idx: number]: {x: 0, y: 0}; +>idx : Symbol(idx, Decl(index.js, 67, 5)) +>x : Symbol(x, Decl(index.js, 67, 20)) +>y : Symbol(y, Decl(index.js, 67, 25)) +} + diff --git a/tests/baselines/reference/jsDeclarationsClassesErr.types b/tests/baselines/reference/jsDeclarationsClassesErr.types new file mode 100644 index 0000000000000..83827f2658c9c --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsClassesErr.types @@ -0,0 +1,148 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// Pretty much all of this should be an error, (since index signatures and generics are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export class M { +>M : M + + field: T; +>field : T +} + +export class N extends M { +>N : N +>M : M + + other: U; +>other : U +} + +export class O { +>O : O + + [idx: string]: string; +>idx : string +} + +export class P extends O {} +>P : P +>O : O + +export class Q extends O { +>Q : Q +>O : O + + [idx: string]: "ok"; +>idx : string +} + +export class R extends O { +>R : R +>O : O + + [idx: number]: "ok"; +>idx : number +} + +export class S extends O { +>S : S +>O : O + + [idx: string]: "ok"; +>idx : string + + [idx: number]: never; +>idx : number +} + +export class T { +>T : T + + [idx: number]: string; +>idx : number +} + +export class U extends T {} +>U : U +>T : T + + +export class V extends T { +>V : V +>T : T + + [idx: string]: string; +>idx : string +} + +export class W extends T { +>W : W +>T : T + + [idx: number]: "ok"; +>idx : number +} + +export class X extends T { +>X : X +>T : T + + [idx: string]: string; +>idx : string + + [idx: number]: "ok"; +>idx : number +} + +export class Y { +>Y : Y + + [idx: string]: {x: number}; +>idx : string +>x : number + + [idx: number]: {x: number, y: number}; +>idx : number +>x : number +>y : number +} + +export class Z extends Y {} +>Z : Z +>Y : Y + +export class AA extends Y { +>AA : AA +>Y : Y + + [idx: string]: {x: number, y: number}; +>idx : string +>x : number +>y : number +} + +export class BB extends Y { +>BB : BB +>Y : Y + + [idx: number]: {x: 0, y: 0}; +>idx : number +>x : 0 +>y : 0 +} + +export class CC extends Y { +>CC : CC +>Y : Y + + [idx: string]: {x: number, y: number}; +>idx : string +>x : number +>y : number + + [idx: number]: {x: 0, y: 0}; +>idx : number +>x : 0 +>y : 0 +} + diff --git a/tests/baselines/reference/jsDeclarationsComputedNames.js b/tests/baselines/reference/jsDeclarationsComputedNames.js new file mode 100644 index 0000000000000..bbc3d5fa0ca61 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsComputedNames.js @@ -0,0 +1,92 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsComputedNames.ts] //// + +//// [index.js] +const TopLevelSym = Symbol(); +const InnerSym = Symbol(); +module.exports = { + [TopLevelSym](x = 12) { + return x; + }, + items: { + [InnerSym]: (arg = {x: 12}) => arg.x + } +} + +//// [index2.js] +const TopLevelSym = Symbol(); +const InnerSym = Symbol(); + +export class MyClass { + static [TopLevelSym] = 12; + [InnerSym] = "ok"; + /** + * @param {typeof TopLevelSym | typeof InnerSym} _p + */ + constructor(_p = InnerSym) { + // switch on _p + } +} + + +//// [index.js] +var _a, _b; +var TopLevelSym = Symbol(); +var InnerSym = Symbol(); +module.exports = (_a = {}, + _a[TopLevelSym] = function (x) { + if (x === void 0) { x = 12; } + return x; + }, + _a.items = (_b = {}, + _b[InnerSym] = function (arg) { + if (arg === void 0) { arg = { x: 12 }; } + return arg.x; + }, + _b), + _a); +//// [index2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var TopLevelSym = Symbol(); +var InnerSym = Symbol(); +var MyClass = /** @class */ (function () { + /** + * @param {typeof TopLevelSym | typeof InnerSym} _p + */ + function MyClass(_p) { + if (_p === void 0) { _p = InnerSym; } + this[_b] = "ok"; + // switch on _p + } + var _a, _b; + _a = TopLevelSym, _b = InnerSym; + MyClass[_a] = 12; + return MyClass; +}()); +exports.MyClass = MyClass; + + +//// [index.d.ts] +declare const _exports: { + [TopLevelSym](x?: number): number; + items: { + [InnerSym]: (arg?: { + x: number; + }) => number; + }; +}; +export = _exports; +declare const TopLevelSym: unique symbol; +declare const InnerSym: unique symbol; +//// [index2.d.ts] +export class MyClass { + static [TopLevelSym]: number; + /** + * @param {typeof TopLevelSym | typeof InnerSym} _p + */ + constructor(_p?: typeof TopLevelSym | typeof InnerSym); + [InnerSym]: string; +} +declare const InnerSym: unique symbol; +declare const TopLevelSym: unique symbol; +export {}; diff --git a/tests/baselines/reference/jsDeclarationsComputedNames.symbols b/tests/baselines/reference/jsDeclarationsComputedNames.symbols new file mode 100644 index 0000000000000..2abc98e4edfc3 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsComputedNames.symbols @@ -0,0 +1,68 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const TopLevelSym = Symbol(); +>TopLevelSym : Symbol(TopLevelSym, Decl(index.js, 0, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +const InnerSym = Symbol(); +>InnerSym : Symbol(InnerSym, Decl(index.js, 1, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +module.exports = { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 1, 26)) +>exports : Symbol(export=, Decl(index.js, 1, 26)) + + [TopLevelSym](x = 12) { +>[TopLevelSym] : Symbol([TopLevelSym], Decl(index.js, 2, 18)) +>TopLevelSym : Symbol(TopLevelSym, Decl(index.js, 0, 5)) +>x : Symbol(x, Decl(index.js, 3, 18)) + + return x; +>x : Symbol(x, Decl(index.js, 3, 18)) + + }, + items: { +>items : Symbol(items, Decl(index.js, 5, 6)) + + [InnerSym]: (arg = {x: 12}) => arg.x +>[InnerSym] : Symbol([InnerSym], Decl(index.js, 6, 12)) +>InnerSym : Symbol(InnerSym, Decl(index.js, 1, 5)) +>arg : Symbol(arg, Decl(index.js, 7, 21)) +>x : Symbol(x, Decl(index.js, 7, 28)) +>arg.x : Symbol(x, Decl(index.js, 7, 28)) +>arg : Symbol(arg, Decl(index.js, 7, 21)) +>x : Symbol(x, Decl(index.js, 7, 28)) + } +} + +=== tests/cases/conformance/jsdoc/declarations/index2.js === +const TopLevelSym = Symbol(); +>TopLevelSym : Symbol(TopLevelSym, Decl(index2.js, 0, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +const InnerSym = Symbol(); +>InnerSym : Symbol(InnerSym, Decl(index2.js, 1, 5)) +>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) + +export class MyClass { +>MyClass : Symbol(MyClass, Decl(index2.js, 1, 26)) + + static [TopLevelSym] = 12; +>[TopLevelSym] : Symbol(MyClass[TopLevelSym], Decl(index2.js, 3, 22)) +>TopLevelSym : Symbol(TopLevelSym, Decl(index2.js, 0, 5)) + + [InnerSym] = "ok"; +>[InnerSym] : Symbol(MyClass[InnerSym], Decl(index2.js, 4, 30)) +>InnerSym : Symbol(InnerSym, Decl(index2.js, 1, 5)) + + /** + * @param {typeof TopLevelSym | typeof InnerSym} _p + */ + constructor(_p = InnerSym) { +>_p : Symbol(_p, Decl(index2.js, 9, 16)) +>InnerSym : Symbol(InnerSym, Decl(index2.js, 1, 5)) + + // switch on _p + } +} + diff --git a/tests/baselines/reference/jsDeclarationsComputedNames.types b/tests/baselines/reference/jsDeclarationsComputedNames.types new file mode 100644 index 0000000000000..ce79ab661c982 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsComputedNames.types @@ -0,0 +1,81 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const TopLevelSym = Symbol(); +>TopLevelSym : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +const InnerSym = Symbol(); +>InnerSym : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +module.exports = { +>module.exports = { [TopLevelSym](x = 12) { return x; }, items: { [InnerSym]: (arg = {x: 12}) => arg.x }} : { [TopLevelSym](x?: number): number; items: { [InnerSym]: (arg?: { x: number; }) => number; }; } +>module.exports : { [TopLevelSym](x?: number): number; items: { [InnerSym]: (arg?: { x: number; }) => number; }; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { [TopLevelSym](x?: number): number; items: { [InnerSym]: (arg?: { x: number; }) => number; }; }; } +>exports : { [TopLevelSym](x?: number): number; items: { [InnerSym]: (arg?: { x: number; }) => number; }; } +>{ [TopLevelSym](x = 12) { return x; }, items: { [InnerSym]: (arg = {x: 12}) => arg.x }} : { [TopLevelSym](x?: number): number; items: { [InnerSym]: (arg?: { x: number; }) => number; }; } + + [TopLevelSym](x = 12) { +>[TopLevelSym] : (x?: number) => number +>TopLevelSym : unique symbol +>x : number +>12 : 12 + + return x; +>x : number + + }, + items: { +>items : { [InnerSym]: (arg?: { x: number; }) => number; } +>{ [InnerSym]: (arg = {x: 12}) => arg.x } : { [InnerSym]: (arg?: { x: number; }) => number; } + + [InnerSym]: (arg = {x: 12}) => arg.x +>[InnerSym] : (arg?: { x: number; }) => number +>InnerSym : unique symbol +>(arg = {x: 12}) => arg.x : (arg?: { x: number; }) => number +>arg : { x: number; } +>{x: 12} : { x: number; } +>x : number +>12 : 12 +>arg.x : number +>arg : { x: number; } +>x : number + } +} + +=== tests/cases/conformance/jsdoc/declarations/index2.js === +const TopLevelSym = Symbol(); +>TopLevelSym : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +const InnerSym = Symbol(); +>InnerSym : unique symbol +>Symbol() : unique symbol +>Symbol : SymbolConstructor + +export class MyClass { +>MyClass : MyClass + + static [TopLevelSym] = 12; +>[TopLevelSym] : number +>TopLevelSym : unique symbol +>12 : 12 + + [InnerSym] = "ok"; +>[InnerSym] : string +>InnerSym : unique symbol +>"ok" : "ok" + + /** + * @param {typeof TopLevelSym | typeof InnerSym} _p + */ + constructor(_p = InnerSym) { +>_p : unique symbol | unique symbol +>InnerSym : unique symbol + + // switch on _p + } +} + diff --git a/tests/baselines/reference/jsDeclarationsDefault.js b/tests/baselines/reference/jsDeclarationsDefault.js new file mode 100644 index 0000000000000..a7d8b248a39ce --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDefault.js @@ -0,0 +1,141 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault.ts] //// + +//// [index1.js] +export default 12; + +//// [index2.js] +export default function foo() { + return foo; +} +export const x = foo; +export { foo as bar }; + +//// [index3.js] +export default class Foo { + a = /** @type {Foo} */(null); +}; +export const X = Foo; +export { Foo as Bar }; + +//// [index4.js] +import Fab from "./index3"; +class Bar extends Fab { + x = /** @type {Bar} */(null); +} +export default Bar; + +//// [index5.js] +// merge type alias and const (OK) +export default 12; +/** + * @typedef {string | number} default + */ + +//// [index6.js] +// merge type alias and function (OK) +export default function func() {}; +/** + * @typedef {string | number} default + */ + + +//// [index1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = 12; +//// [index2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { + return foo; +} +exports.default = foo; +exports.bar = foo; +exports.x = foo; +//// [index3.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + this.a = (null); + } + return Foo; +}()); +exports.Bar = Foo; +exports.default = Foo; +; +exports.X = Foo; +//// [index4.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); +var index3_1 = require("./index3"); +var Bar = /** @class */ (function (_super) { + __extends(Bar, _super); + function Bar() { + var _this = _super !== null && _super.apply(this, arguments) || this; + _this.x = (null); + return _this; + } + return Bar; +}(index3_1.default)); +exports.default = Bar; +//// [index5.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// merge type alias and const (OK) +exports.default = 12; +/** + * @typedef {string | number} default + */ +//// [index6.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// merge type alias and function (OK) +function func() { } +exports.default = func; +; +/** + * @typedef {string | number} default + */ + + +//// [index1.d.ts] +declare var _default: 12; +export default _default; +//// [index2.d.ts] +export default function foo(): typeof foo; +export function x(): typeof foo; +export { foo as bar }; +//// [index3.d.ts] +export default class Foo { + a: Foo; +} +export const X: typeof Foo; +export { Foo as Bar }; +//// [index4.d.ts] +export default Bar; +declare class Bar extends Fab { + x: Bar; +} +import Fab from "./index3"; +//// [index5.d.ts] +type _default = string | number; +declare var _default: 12; +export default _default; +//// [index6.d.ts] +declare function func(): void; +type func = string | number; +export default func; diff --git a/tests/baselines/reference/jsDeclarationsDefault.symbols b/tests/baselines/reference/jsDeclarationsDefault.symbols new file mode 100644 index 0000000000000..4436c83d40ec0 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDefault.symbols @@ -0,0 +1,64 @@ +=== tests/cases/conformance/jsdoc/declarations/index1.js === +export default 12; +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/index2.js === +export default function foo() { +>foo : Symbol(foo, Decl(index2.js, 0, 0)) + + return foo; +>foo : Symbol(foo, Decl(index2.js, 0, 0)) +} +export const x = foo; +>x : Symbol(x, Decl(index2.js, 3, 12)) +>foo : Symbol(foo, Decl(index2.js, 0, 0)) + +export { foo as bar }; +>foo : Symbol(foo, Decl(index2.js, 0, 0)) +>bar : Symbol(bar, Decl(index2.js, 4, 8)) + +=== tests/cases/conformance/jsdoc/declarations/index3.js === +export default class Foo { +>Foo : Symbol(Foo, Decl(index3.js, 0, 0)) + + a = /** @type {Foo} */(null); +>a : Symbol(Foo.a, Decl(index3.js, 0, 26)) + +}; +export const X = Foo; +>X : Symbol(X, Decl(index3.js, 3, 12)) +>Foo : Symbol(Foo, Decl(index3.js, 0, 0)) + +export { Foo as Bar }; +>Foo : Symbol(Foo, Decl(index3.js, 0, 0)) +>Bar : Symbol(Bar, Decl(index3.js, 4, 8)) + +=== tests/cases/conformance/jsdoc/declarations/index4.js === +import Fab from "./index3"; +>Fab : Symbol(Fab, Decl(index4.js, 0, 6)) + +class Bar extends Fab { +>Bar : Symbol(Bar, Decl(index4.js, 0, 27)) +>Fab : Symbol(Fab, Decl(index4.js, 0, 6)) + + x = /** @type {Bar} */(null); +>x : Symbol(Bar.x, Decl(index4.js, 1, 23)) +} +export default Bar; +>Bar : Symbol(Bar, Decl(index4.js, 0, 27)) + +=== tests/cases/conformance/jsdoc/declarations/index5.js === +// merge type alias and const (OK) +No type information for this code.export default 12; +No type information for this code./** +No type information for this code. * @typedef {string | number} default +No type information for this code. */ +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/index6.js === +// merge type alias and function (OK) +export default function func() {}; +>func : Symbol(func, Decl(index6.js, 0, 0), Decl(index6.js, 3, 3)) + +/** + * @typedef {string | number} default + */ + diff --git a/tests/baselines/reference/jsDeclarationsDefault.types b/tests/baselines/reference/jsDeclarationsDefault.types new file mode 100644 index 0000000000000..df45a2a221c2f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDefault.types @@ -0,0 +1,68 @@ +=== tests/cases/conformance/jsdoc/declarations/index1.js === +export default 12; +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/index2.js === +export default function foo() { +>foo : () => typeof foo + + return foo; +>foo : () => typeof foo +} +export const x = foo; +>x : () => typeof foo +>foo : () => typeof foo + +export { foo as bar }; +>foo : () => typeof foo +>bar : () => typeof foo + +=== tests/cases/conformance/jsdoc/declarations/index3.js === +export default class Foo { +>Foo : Foo + + a = /** @type {Foo} */(null); +>a : Foo +>(null) : Foo +>null : null + +}; +export const X = Foo; +>X : typeof Foo +>Foo : typeof Foo + +export { Foo as Bar }; +>Foo : typeof Foo +>Bar : typeof Foo + +=== tests/cases/conformance/jsdoc/declarations/index4.js === +import Fab from "./index3"; +>Fab : typeof Fab + +class Bar extends Fab { +>Bar : Bar +>Fab : Fab + + x = /** @type {Bar} */(null); +>x : Bar +>(null) : Bar +>null : null +} +export default Bar; +>Bar : Bar + +=== tests/cases/conformance/jsdoc/declarations/index5.js === +// merge type alias and const (OK) +No type information for this code.export default 12; +No type information for this code./** +No type information for this code. * @typedef {string | number} default +No type information for this code. */ +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/index6.js === +// merge type alias and function (OK) +export default function func() {}; +>func : () => void + +/** + * @typedef {string | number} default + */ + diff --git a/tests/baselines/reference/jsDeclarationsDefaultsErr.errors.txt b/tests/baselines/reference/jsDeclarationsDefaultsErr.errors.txt new file mode 100644 index 0000000000000..8c8f7c36e66f3 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDefaultsErr.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/jsdoc/declarations/index2.js(2,22): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/jsdoc/declarations/index2.js(4,31): error TS2300: Duplicate identifier 'default'. + + +==== tests/cases/conformance/jsdoc/declarations/index1.js (0 errors) ==== + // merge type alias and alias (should error, see #32367) + class Cls { + x = 12; + static y = "ok" + } + export default Cls; + /** + * @typedef {string | number} default + */ + +==== tests/cases/conformance/jsdoc/declarations/index2.js (2 errors) ==== + // merge type alias and class (error message improvement needed, see #32368) + export default class C {}; + ~ +!!! error TS2300: Duplicate identifier 'C'. + /** + * @typedef {string | number} default + ~~~~~~~ +!!! error TS2300: Duplicate identifier 'default'. + */ + +==== tests/cases/conformance/jsdoc/declarations/index3.js (0 errors) ==== + // merge type alias and variable (behavior is borked, see #32366) + const x = 12; + export {x as default}; + /** + * @typedef {string | number} default + */ + \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsDefaultsErr.js b/tests/baselines/reference/jsDeclarationsDefaultsErr.js new file mode 100644 index 0000000000000..ddc7a0328187b --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDefaultsErr.js @@ -0,0 +1,83 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefaultsErr.ts] //// + +//// [index1.js] +// merge type alias and alias (should error, see #32367) +class Cls { + x = 12; + static y = "ok" +} +export default Cls; +/** + * @typedef {string | number} default + */ + +//// [index2.js] +// merge type alias and class (error message improvement needed, see #32368) +export default class C {}; +/** + * @typedef {string | number} default + */ + +//// [index3.js] +// merge type alias and variable (behavior is borked, see #32366) +const x = 12; +export {x as default}; +/** + * @typedef {string | number} default + */ + + +//// [index1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// merge type alias and alias (should error, see #32367) +var Cls = /** @class */ (function () { + function Cls() { + this.x = 12; + } + Cls.y = "ok"; + return Cls; +}()); +exports.default = Cls; +/** + * @typedef {string | number} default + */ +//// [index2.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// merge type alias and class (error message improvement needed, see #32368) +var C = /** @class */ (function () { + function C() { + } + return C; +}()); +exports.default = C; +; +/** + * @typedef {string | number} default + */ +//// [index3.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +// merge type alias and variable (behavior is borked, see #32366) +var x = 12; +exports.default = x; +/** + * @typedef {string | number} default + */ + + +//// [index1.d.ts] +export type Cls = string | number; +export default Cls; +declare class Cls { + static y: string; + x: number; +} +//// [index2.d.ts] +export default class C { +} +//// [index3.d.ts] +export type _default = string | number; +export { x as default }; +declare const x: 12; diff --git a/tests/baselines/reference/jsDeclarationsDefaultsErr.symbols b/tests/baselines/reference/jsDeclarationsDefaultsErr.symbols new file mode 100644 index 0000000000000..e21977c355d70 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDefaultsErr.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/jsdoc/declarations/index1.js === +// merge type alias and alias (should error, see #32367) +class Cls { +>Cls : Symbol(Cls, Decl(index1.js, 0, 0)) + + x = 12; +>x : Symbol(Cls.x, Decl(index1.js, 1, 11)) + + static y = "ok" +>y : Symbol(Cls.y, Decl(index1.js, 2, 11)) +} +export default Cls; +>Cls : Symbol(Cls, Decl(index1.js, 0, 0)) + +/** + * @typedef {string | number} default + */ + +=== tests/cases/conformance/jsdoc/declarations/index2.js === +// merge type alias and class (error message improvement needed, see #32368) +export default class C {}; +>C : Symbol(C, Decl(index2.js, 0, 0)) + +/** + * @typedef {string | number} default + */ + +=== tests/cases/conformance/jsdoc/declarations/index3.js === +// merge type alias and variable (behavior is borked, see #32366) +const x = 12; +>x : Symbol(x, Decl(index3.js, 1, 5)) + +export {x as default}; +>x : Symbol(x, Decl(index3.js, 1, 5)) +>default : Symbol(default, Decl(index3.js, 2, 8), Decl(index3.js, 4, 3)) + +/** + * @typedef {string | number} default + */ + diff --git a/tests/baselines/reference/jsDeclarationsDefaultsErr.types b/tests/baselines/reference/jsDeclarationsDefaultsErr.types new file mode 100644 index 0000000000000..8580c1514e433 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsDefaultsErr.types @@ -0,0 +1,43 @@ +=== tests/cases/conformance/jsdoc/declarations/index1.js === +// merge type alias and alias (should error, see #32367) +class Cls { +>Cls : Cls + + x = 12; +>x : number +>12 : 12 + + static y = "ok" +>y : string +>"ok" : "ok" +} +export default Cls; +>Cls : Cls + +/** + * @typedef {string | number} default + */ + +=== tests/cases/conformance/jsdoc/declarations/index2.js === +// merge type alias and class (error message improvement needed, see #32368) +export default class C {}; +>C : C + +/** + * @typedef {string | number} default + */ + +=== tests/cases/conformance/jsdoc/declarations/index3.js === +// merge type alias and variable (behavior is borked, see #32366) +const x = 12; +>x : 12 +>12 : 12 + +export {x as default}; +>x : 12 +>default : 12 + +/** + * @typedef {string | number} default + */ + diff --git a/tests/baselines/reference/jsDeclarationsEnumTag.js b/tests/baselines/reference/jsDeclarationsEnumTag.js new file mode 100644 index 0000000000000..7e938fbbdd4ab --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsEnumTag.js @@ -0,0 +1,130 @@ +//// [index.js] +/** @enum {string} */ +export const Target = { + START: "start", + MIDDLE: "middle", + END: "end", + /** @type {number} */ + OK_I_GUESS: 2 +} +/** @enum number */ +export const Second = { + OK: 1, + /** @type {number} */ + FINE: 2, +} +/** @enum {function(number): number} */ +export const Fs = { + ADD1: n => n + 1, + ID: n => n, + SUB1: n => n - 1 +} + +/** + * @param {Target} t + * @param {Second} s + * @param {Fs} f + */ +export function consume(t,s,f) { + /** @type {string} */ + var str = t + /** @type {number} */ + var num = s + /** @type {(n: number) => number} */ + var fun = f + /** @type {Target} */ + var v = Target.START + v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums +} +/** @param {string} s */ +export function ff(s) { + // element access with arbitrary string is an error only with noImplicitAny + if (!Target[s]) { + return null + } + else { + return Target[s] + } +} + + +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** @enum {string} */ +exports.Target = { + START: "start", + MIDDLE: "middle", + END: "end", + /** @type {number} */ + OK_I_GUESS: 2 +}; +/** @enum number */ +exports.Second = { + OK: 1, + /** @type {number} */ + FINE: 2, +}; +/** @enum {function(number): number} */ +exports.Fs = { + ADD1: function (n) { return n + 1; }, + ID: function (n) { return n; }, + SUB1: function (n) { return n - 1; } +}; +/** + * @param {Target} t + * @param {Second} s + * @param {Fs} f + */ +function consume(t, s, f) { + /** @type {string} */ + var str = t; + /** @type {number} */ + var num = s; + /** @type {(n: number) => number} */ + var fun = f; + /** @type {Target} */ + var v = exports.Target.START; + v = 'something else'; // allowed, like Typescript's classic enums and unlike its string enums +} +exports.consume = consume; +/** @param {string} s */ +function ff(s) { + // element access with arbitrary string is an error only with noImplicitAny + if (!exports.Target[s]) { + return null; + } + else { + return exports.Target[s]; + } +} +exports.ff = ff; + + +//// [index.d.ts] +/** + * @param {Target} t + * @param {Second} s + * @param {Fs} f + */ +export function consume(t: string, s: number, f: (arg0: number) => number): void; +/** @param {string} s */ +export function ff(s: string): any; +export type Target = string; +export namespace Target { + export const START: string; + export const MIDDLE: string; + export const END: string; + export const OK_I_GUESS: number; +} +export type Second = number; +export namespace Second { + export const OK: number; + export const FINE: number; +} +export type Fs = (arg0: number) => number; +export namespace Fs { + export function ADD1(n: any): any; + export function ID(n: any): any; + export function SUB1(n: any): number; +} diff --git a/tests/baselines/reference/jsDeclarationsEnumTag.symbols b/tests/baselines/reference/jsDeclarationsEnumTag.symbols new file mode 100644 index 0000000000000..d2e73aaca5a55 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsEnumTag.symbols @@ -0,0 +1,104 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** @enum {string} */ +export const Target = { +>Target : Symbol(Target, Decl(index.js, 1, 12), Decl(index.js, 0, 4)) + + START: "start", +>START : Symbol(START, Decl(index.js, 1, 23)) + + MIDDLE: "middle", +>MIDDLE : Symbol(MIDDLE, Decl(index.js, 2, 19)) + + END: "end", +>END : Symbol(END, Decl(index.js, 3, 21)) + + /** @type {number} */ + OK_I_GUESS: 2 +>OK_I_GUESS : Symbol(OK_I_GUESS, Decl(index.js, 4, 15)) +} +/** @enum number */ +export const Second = { +>Second : Symbol(Second, Decl(index.js, 9, 12), Decl(index.js, 8, 4)) + + OK: 1, +>OK : Symbol(OK, Decl(index.js, 9, 23)) + + /** @type {number} */ + FINE: 2, +>FINE : Symbol(FINE, Decl(index.js, 10, 10)) +} +/** @enum {function(number): number} */ +export const Fs = { +>Fs : Symbol(Fs, Decl(index.js, 15, 12), Decl(index.js, 14, 4)) + + ADD1: n => n + 1, +>ADD1 : Symbol(ADD1, Decl(index.js, 15, 19)) +>n : Symbol(n, Decl(index.js, 16, 9)) +>n : Symbol(n, Decl(index.js, 16, 9)) + + ID: n => n, +>ID : Symbol(ID, Decl(index.js, 16, 21)) +>n : Symbol(n, Decl(index.js, 17, 7)) +>n : Symbol(n, Decl(index.js, 17, 7)) + + SUB1: n => n - 1 +>SUB1 : Symbol(SUB1, Decl(index.js, 17, 15)) +>n : Symbol(n, Decl(index.js, 18, 9)) +>n : Symbol(n, Decl(index.js, 18, 9)) +} + +/** + * @param {Target} t + * @param {Second} s + * @param {Fs} f + */ +export function consume(t,s,f) { +>consume : Symbol(consume, Decl(index.js, 19, 1)) +>t : Symbol(t, Decl(index.js, 26, 24)) +>s : Symbol(s, Decl(index.js, 26, 26)) +>f : Symbol(f, Decl(index.js, 26, 28)) + + /** @type {string} */ + var str = t +>str : Symbol(str, Decl(index.js, 28, 7)) +>t : Symbol(t, Decl(index.js, 26, 24)) + + /** @type {number} */ + var num = s +>num : Symbol(num, Decl(index.js, 30, 7)) +>s : Symbol(s, Decl(index.js, 26, 26)) + + /** @type {(n: number) => number} */ + var fun = f +>fun : Symbol(fun, Decl(index.js, 32, 7)) +>f : Symbol(f, Decl(index.js, 26, 28)) + + /** @type {Target} */ + var v = Target.START +>v : Symbol(v, Decl(index.js, 34, 7)) +>Target.START : Symbol(START, Decl(index.js, 1, 23)) +>Target : Symbol(Target, Decl(index.js, 1, 12), Decl(index.js, 0, 4)) +>START : Symbol(START, Decl(index.js, 1, 23)) + + v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums +>v : Symbol(v, Decl(index.js, 34, 7)) +} +/** @param {string} s */ +export function ff(s) { +>ff : Symbol(ff, Decl(index.js, 36, 1)) +>s : Symbol(s, Decl(index.js, 38, 19)) + + // element access with arbitrary string is an error only with noImplicitAny + if (!Target[s]) { +>Target : Symbol(Target, Decl(index.js, 1, 12), Decl(index.js, 0, 4)) +>s : Symbol(s, Decl(index.js, 38, 19)) + + return null + } + else { + return Target[s] +>Target : Symbol(Target, Decl(index.js, 1, 12), Decl(index.js, 0, 4)) +>s : Symbol(s, Decl(index.js, 38, 19)) + } +} + diff --git a/tests/baselines/reference/jsDeclarationsEnumTag.types b/tests/baselines/reference/jsDeclarationsEnumTag.types new file mode 100644 index 0000000000000..642ee7d6490fd --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsEnumTag.types @@ -0,0 +1,126 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** @enum {string} */ +export const Target = { +>Target : { START: string; MIDDLE: string; END: string; OK_I_GUESS: number; } +>{ START: "start", MIDDLE: "middle", END: "end", /** @type {number} */ OK_I_GUESS: 2} : { START: string; MIDDLE: string; END: string; OK_I_GUESS: number; } + + START: "start", +>START : string +>"start" : "start" + + MIDDLE: "middle", +>MIDDLE : string +>"middle" : "middle" + + END: "end", +>END : string +>"end" : "end" + + /** @type {number} */ + OK_I_GUESS: 2 +>OK_I_GUESS : number +>2 : 2 +} +/** @enum number */ +export const Second = { +>Second : { OK: number; FINE: number; } +>{ OK: 1, /** @type {number} */ FINE: 2,} : { OK: number; FINE: number; } + + OK: 1, +>OK : number +>1 : 1 + + /** @type {number} */ + FINE: 2, +>FINE : number +>2 : 2 +} +/** @enum {function(number): number} */ +export const Fs = { +>Fs : { ADD1: (n: any) => any; ID: (n: any) => any; SUB1: (n: any) => number; } +>{ ADD1: n => n + 1, ID: n => n, SUB1: n => n - 1} : { ADD1: (n: any) => any; ID: (n: any) => any; SUB1: (n: any) => number; } + + ADD1: n => n + 1, +>ADD1 : (n: any) => any +>n => n + 1 : (n: any) => any +>n : any +>n + 1 : any +>n : any +>1 : 1 + + ID: n => n, +>ID : (n: any) => any +>n => n : (n: any) => any +>n : any +>n : any + + SUB1: n => n - 1 +>SUB1 : (n: any) => number +>n => n - 1 : (n: any) => number +>n : any +>n - 1 : number +>n : any +>1 : 1 +} + +/** + * @param {Target} t + * @param {Second} s + * @param {Fs} f + */ +export function consume(t,s,f) { +>consume : (t: string, s: number, f: (arg0: number) => number) => void +>t : string +>s : number +>f : (arg0: number) => number + + /** @type {string} */ + var str = t +>str : string +>t : string + + /** @type {number} */ + var num = s +>num : number +>s : number + + /** @type {(n: number) => number} */ + var fun = f +>fun : (n: number) => number +>f : (arg0: number) => number + + /** @type {Target} */ + var v = Target.START +>v : string +>Target.START : string +>Target : { START: string; MIDDLE: string; END: string; OK_I_GUESS: number; } +>START : string + + v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums +>v = 'something else' : "something else" +>v : string +>'something else' : "something else" +} +/** @param {string} s */ +export function ff(s) { +>ff : (s: string) => any +>s : string + + // element access with arbitrary string is an error only with noImplicitAny + if (!Target[s]) { +>!Target[s] : boolean +>Target[s] : error +>Target : { START: string; MIDDLE: string; END: string; OK_I_GUESS: number; } +>s : string + + return null +>null : null + } + else { + return Target[s] +>Target[s] : error +>Target : { START: string; MIDDLE: string; END: string; OK_I_GUESS: number; } +>s : string + } +} + diff --git a/tests/baselines/reference/jsDeclarationsEnums.errors.txt b/tests/baselines/reference/jsDeclarationsEnums.errors.txt new file mode 100644 index 0000000000000..630d4aab7e9ad --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsEnums.errors.txt @@ -0,0 +1,101 @@ +tests/cases/conformance/jsdoc/declarations/index.js(4,13): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(6,13): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(10,6): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(14,6): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(18,13): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(22,13): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(24,13): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(30,13): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(35,13): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(41,19): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(47,13): error TS8015: 'enum declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(55,19): error TS8015: 'enum declarations' can only be used in a .ts file. + + +==== tests/cases/conformance/jsdoc/declarations/index.js (12 errors) ==== + // Pretty much all of this should be an error, (since enums are forbidden in js), + // but we should be able to synthesize declarations from the symbols regardless + + export enum A {} + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + + export enum B { + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + Member + } + + enum C {} + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + + export { C }; + + enum DD {} + ~~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + + export { DD as D }; + + export enum E {} + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + export { E as EE }; + + export { F as FF }; + export enum F {} + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + + export enum G { + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + A = 1, + B, + C + } + + export enum H { + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + A = "a", + B = "b" + } + + export enum I { + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + A = "a", + B = 0, + C + } + + export const enum J { + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + A = 1, + B, + C + } + + export enum K { + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + None = 0, + A = 1 << 0, + B = 1 << 1, + C = 1 << 2, + Mask = A | B | C, + } + + export const enum L { + ~ +!!! error TS8015: 'enum declarations' can only be used in a .ts file. + None = 0, + A = 1 << 0, + B = 1 << 1, + C = 1 << 2, + Mask = A | B | C, + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsEnums.js b/tests/baselines/reference/jsDeclarationsEnums.js new file mode 100644 index 0000000000000..3fc6201b904ae --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsEnums.js @@ -0,0 +1,167 @@ +//// [index.js] +// Pretty much all of this should be an error, (since enums are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export enum A {} + +export enum B { + Member +} + +enum C {} + +export { C }; + +enum DD {} + +export { DD as D }; + +export enum E {} +export { E as EE }; + +export { F as FF }; +export enum F {} + +export enum G { + A = 1, + B, + C +} + +export enum H { + A = "a", + B = "b" +} + +export enum I { + A = "a", + B = 0, + C +} + +export const enum J { + A = 1, + B, + C +} + +export enum K { + None = 0, + A = 1 << 0, + B = 1 << 1, + C = 1 << 2, + Mask = A | B | C, +} + +export const enum L { + None = 0, + A = 1 << 0, + B = 1 << 1, + C = 1 << 2, + Mask = A | B | C, +} + + +//// [index.js] +"use strict"; +// Pretty much all of this should be an error, (since enums are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless +Object.defineProperty(exports, "__esModule", { value: true }); +var A; +(function (A) { +})(A = exports.A || (exports.A = {})); +var B; +(function (B) { + B[B["Member"] = 0] = "Member"; +})(B = exports.B || (exports.B = {})); +var C; +(function (C) { +})(C || (C = {})); +exports.C = C; +var DD; +(function (DD) { +})(DD || (DD = {})); +exports.D = DD; +var E; +(function (E) { +})(E = exports.E || (exports.E = {})); +exports.EE = E; +var F; +(function (F) { +})(F = exports.F || (exports.F = {})); +exports.FF = F; +var G; +(function (G) { + G[G["A"] = 1] = "A"; + G[G["B"] = 2] = "B"; + G[G["C"] = 3] = "C"; +})(G = exports.G || (exports.G = {})); +var H; +(function (H) { + H["A"] = "a"; + H["B"] = "b"; +})(H = exports.H || (exports.H = {})); +var I; +(function (I) { + I["A"] = "a"; + I[I["B"] = 0] = "B"; + I[I["C"] = 1] = "C"; +})(I = exports.I || (exports.I = {})); +var K; +(function (K) { + K[K["None"] = 0] = "None"; + K[K["A"] = 1] = "A"; + K[K["B"] = 2] = "B"; + K[K["C"] = 4] = "C"; + K[K["Mask"] = 7] = "Mask"; +})(K = exports.K || (exports.K = {})); + + +//// [index.d.ts] +export enum A { +} +export enum B { + Member = 0 +} +export enum E { +} +export enum F { +} +export enum G { + A = 1, + B = 2, + C = 3 +} +export enum H { + A = "a", + B = "b" +} +export enum I { + A = "a", + B = 0, + C = 1 +} +export const enum J { + A = 1, + B = 2, + C = 3 +} +export enum K { + None = 0, + A = 1, + B = 2, + C = 4, + Mask = 7 +} +export const enum L { + None = 0, + A = 1, + B = 2, + C = 4, + Mask = 7 +} +export enum C { +} +declare enum DD { +} +export { DD as D, E as EE, F as FF }; diff --git a/tests/baselines/reference/jsDeclarationsEnums.symbols b/tests/baselines/reference/jsDeclarationsEnums.symbols new file mode 100644 index 0000000000000..7980af3801920 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsEnums.symbols @@ -0,0 +1,134 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// Pretty much all of this should be an error, (since enums are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export enum A {} +>A : Symbol(A, Decl(index.js, 0, 0)) + +export enum B { +>B : Symbol(B, Decl(index.js, 3, 16)) + + Member +>Member : Symbol(B.Member, Decl(index.js, 5, 15)) +} + +enum C {} +>C : Symbol(C, Decl(index.js, 7, 1)) + +export { C }; +>C : Symbol(C, Decl(index.js, 11, 8)) + +enum DD {} +>DD : Symbol(DD, Decl(index.js, 11, 13)) + +export { DD as D }; +>DD : Symbol(DD, Decl(index.js, 11, 13)) +>D : Symbol(D, Decl(index.js, 15, 8)) + +export enum E {} +>E : Symbol(E, Decl(index.js, 15, 19)) + +export { E as EE }; +>E : Symbol(E, Decl(index.js, 15, 19)) +>EE : Symbol(EE, Decl(index.js, 18, 8)) + +export { F as FF }; +>F : Symbol(F, Decl(index.js, 20, 19)) +>FF : Symbol(FF, Decl(index.js, 20, 8)) + +export enum F {} +>F : Symbol(F, Decl(index.js, 20, 19)) + +export enum G { +>G : Symbol(G, Decl(index.js, 21, 16)) + + A = 1, +>A : Symbol(G.A, Decl(index.js, 23, 15)) + + B, +>B : Symbol(G.B, Decl(index.js, 24, 10)) + + C +>C : Symbol(G.C, Decl(index.js, 25, 6)) +} + +export enum H { +>H : Symbol(H, Decl(index.js, 27, 1)) + + A = "a", +>A : Symbol(H.A, Decl(index.js, 29, 15)) + + B = "b" +>B : Symbol(H.B, Decl(index.js, 30, 12)) +} + +export enum I { +>I : Symbol(I, Decl(index.js, 32, 1)) + + A = "a", +>A : Symbol(I.A, Decl(index.js, 34, 15)) + + B = 0, +>B : Symbol(I.B, Decl(index.js, 35, 12)) + + C +>C : Symbol(I.C, Decl(index.js, 36, 10)) +} + +export const enum J { +>J : Symbol(J, Decl(index.js, 38, 1)) + + A = 1, +>A : Symbol(J.A, Decl(index.js, 40, 21)) + + B, +>B : Symbol(J.B, Decl(index.js, 41, 10)) + + C +>C : Symbol(J.C, Decl(index.js, 42, 6)) +} + +export enum K { +>K : Symbol(K, Decl(index.js, 44, 1)) + + None = 0, +>None : Symbol(K.None, Decl(index.js, 46, 15)) + + A = 1 << 0, +>A : Symbol(K.A, Decl(index.js, 47, 15)) + + B = 1 << 1, +>B : Symbol(K.B, Decl(index.js, 48, 15)) + + C = 1 << 2, +>C : Symbol(K.C, Decl(index.js, 49, 15)) + + Mask = A | B | C, +>Mask : Symbol(K.Mask, Decl(index.js, 50, 15)) +>A : Symbol(K.A, Decl(index.js, 47, 15)) +>B : Symbol(K.B, Decl(index.js, 48, 15)) +>C : Symbol(K.C, Decl(index.js, 49, 15)) +} + +export const enum L { +>L : Symbol(L, Decl(index.js, 52, 1)) + + None = 0, +>None : Symbol(L.None, Decl(index.js, 54, 21)) + + A = 1 << 0, +>A : Symbol(L.A, Decl(index.js, 55, 15)) + + B = 1 << 1, +>B : Symbol(L.B, Decl(index.js, 56, 15)) + + C = 1 << 2, +>C : Symbol(L.C, Decl(index.js, 57, 15)) + + Mask = A | B | C, +>Mask : Symbol(L.Mask, Decl(index.js, 58, 15)) +>A : Symbol(L.A, Decl(index.js, 55, 15)) +>B : Symbol(L.B, Decl(index.js, 56, 15)) +>C : Symbol(L.C, Decl(index.js, 57, 15)) +} + diff --git a/tests/baselines/reference/jsDeclarationsEnums.types b/tests/baselines/reference/jsDeclarationsEnums.types new file mode 100644 index 0000000000000..e01b2637fb663 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsEnums.types @@ -0,0 +1,164 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// Pretty much all of this should be an error, (since enums are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export enum A {} +>A : A + +export enum B { +>B : B + + Member +>Member : B.Member +} + +enum C {} +>C : C + +export { C }; +>C : typeof C + +enum DD {} +>DD : DD + +export { DD as D }; +>DD : typeof DD +>D : typeof DD + +export enum E {} +>E : E + +export { E as EE }; +>E : typeof E +>EE : typeof E + +export { F as FF }; +>F : typeof F +>FF : typeof F + +export enum F {} +>F : F + +export enum G { +>G : G + + A = 1, +>A : G.A +>1 : 1 + + B, +>B : G.B + + C +>C : G.C +} + +export enum H { +>H : H + + A = "a", +>A : H.A +>"a" : "a" + + B = "b" +>B : H.B +>"b" : "b" +} + +export enum I { +>I : I + + A = "a", +>A : I.A +>"a" : "a" + + B = 0, +>B : I.B +>0 : 0 + + C +>C : I.C +} + +export const enum J { +>J : J + + A = 1, +>A : J.A +>1 : 1 + + B, +>B : J.B + + C +>C : J.C +} + +export enum K { +>K : K + + None = 0, +>None : K +>0 : 0 + + A = 1 << 0, +>A : K +>1 << 0 : number +>1 : 1 +>0 : 0 + + B = 1 << 1, +>B : K +>1 << 1 : number +>1 : 1 +>1 : 1 + + C = 1 << 2, +>C : K +>1 << 2 : number +>1 : 1 +>2 : 2 + + Mask = A | B | C, +>Mask : K +>A | B | C : number +>A | B : number +>A : K +>B : K +>C : K +} + +export const enum L { +>L : L + + None = 0, +>None : L +>0 : 0 + + A = 1 << 0, +>A : L +>1 << 0 : number +>1 : 1 +>0 : 0 + + B = 1 << 1, +>B : L +>1 << 1 : number +>1 : 1 +>1 : 1 + + C = 1 << 2, +>C : L +>1 << 2 : number +>1 : 1 +>2 : 2 + + Mask = A | B | C, +>Mask : L +>A | B | C : number +>A | B : number +>A : L +>B : L +>C : L +} + diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.js b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.js new file mode 100644 index 0000000000000..50797f3bc7479 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.js @@ -0,0 +1,31 @@ +//// [index.js] +module.exports = class Thing { + /** + * @param {number} p + */ + constructor(p) { + this.t = 12 + p; + } +} + +//// [index.js] +module.exports = /** @class */ (function () { + /** + * @param {number} p + */ + function Thing(p) { + this.t = 12 + p; + } + return Thing; +}()); + + +//// [index.d.ts] +export = Thing; +declare class Thing { + /** + * @param {number} p + */ + constructor(p: number); + t: number; +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.symbols b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.symbols new file mode 100644 index 0000000000000..3552f73f4a515 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +module.exports = class Thing { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 0, 0)) +>exports : Symbol(export=, Decl(index.js, 0, 0)) +>Thing : Symbol(Thing, Decl(index.js, 0, 16)) + + /** + * @param {number} p + */ + constructor(p) { +>p : Symbol(p, Decl(index.js, 4, 16)) + + this.t = 12 + p; +>this.t : Symbol(Thing.t, Decl(index.js, 4, 20)) +>this : Symbol(Thing, Decl(index.js, 0, 16)) +>t : Symbol(Thing.t, Decl(index.js, 4, 20)) +>p : Symbol(p, Decl(index.js, 4, 16)) + } +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.types b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.types new file mode 100644 index 0000000000000..42dee86cf5061 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpression.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +module.exports = class Thing { +>module.exports = class Thing { /** * @param {number} p */ constructor(p) { this.t = 12 + p; }} : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>class Thing { /** * @param {number} p */ constructor(p) { this.t = 12 + p; }} : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>Thing : typeof import("tests/cases/conformance/jsdoc/declarations/index") + + /** + * @param {number} p + */ + constructor(p) { +>p : number + + this.t = 12 + p; +>this.t = 12 + p : number +>this.t : number +>this : this +>t : number +>12 + p : number +>12 : 12 +>p : number + } +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.js b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.js new file mode 100644 index 0000000000000..74e0e3799c4fb --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.js @@ -0,0 +1,31 @@ +//// [index.js] +module.exports = class { + /** + * @param {number} p + */ + constructor(p) { + this.t = 12 + p; + } +} + +//// [index.js] +module.exports = /** @class */ (function () { + /** + * @param {number} p + */ + function exports(p) { + this.t = 12 + p; + } + return exports; +}()); + + +//// [index.d.ts] +export = exports; +declare class exports { + /** + * @param {number} p + */ + constructor(p: number); + t: number; +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.symbols b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.symbols new file mode 100644 index 0000000000000..b4d32907ff62f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +module.exports = class { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 0, 0)) +>exports : Symbol(export=, Decl(index.js, 0, 0)) + + /** + * @param {number} p + */ + constructor(p) { +>p : Symbol(p, Decl(index.js, 4, 16)) + + this.t = 12 + p; +>this.t : Symbol(exports.t, Decl(index.js, 4, 20)) +>this : Symbol(exports, Decl(index.js, 0, 16)) +>t : Symbol(exports.t, Decl(index.js, 4, 20)) +>p : Symbol(p, Decl(index.js, 4, 16)) + } +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.types b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.types new file mode 100644 index 0000000000000..dfad9afb09be5 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymous.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +module.exports = class { +>module.exports = class { /** * @param {number} p */ constructor(p) { this.t = 12 + p; }} : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>class { /** * @param {number} p */ constructor(p) { this.t = 12 + p; }} : typeof import("tests/cases/conformance/jsdoc/declarations/index") + + /** + * @param {number} p + */ + constructor(p) { +>p : number + + this.t = 12 + p; +>this.t = 12 + p : number +>this.t : number +>this : this +>t : number +>12 + p : number +>12 : 12 +>p : number + } +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js new file mode 100644 index 0000000000000..8177aacbe456c --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.js @@ -0,0 +1,49 @@ +//// [index.js] +module.exports = class { + /** + * @param {number} p + */ + constructor(p) { + this.t = 12 + p; + } +} +module.exports.Sub = class { + constructor() { + this.instance = new module.exports(10); + } +} + + +//// [index.js] +module.exports = /** @class */ (function () { + /** + * @param {number} p + */ + function exports(p) { + this.t = 12 + p; + } + return exports; +}()); +module.exports.Sub = /** @class */ (function () { + function Sub() { + this.instance = new module.exports(10); + } + return Sub; +}()); + + +//// [index.d.ts] +export = exports; +declare class exports { + /** + * @param {number} p + */ + constructor(p: number); + t: number; +} +declare namespace exports { + export { Sub }; +} +declare class Sub { + instance: import("."); +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.symbols b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.symbols new file mode 100644 index 0000000000000..228bb10cccc03 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +module.exports = class { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 0, 0)) +>exports : Symbol(export=, Decl(index.js, 0, 0)) + + /** + * @param {number} p + */ + constructor(p) { +>p : Symbol(p, Decl(index.js, 4, 16)) + + this.t = 12 + p; +>this.t : Symbol(exports.t, Decl(index.js, 4, 20)) +>this : Symbol(exports, Decl(index.js, 0, 16)) +>t : Symbol(exports.t, Decl(index.js, 4, 20)) +>p : Symbol(p, Decl(index.js, 4, 16)) + } +} +module.exports.Sub = class { +>module.exports.Sub : Symbol(Sub) +>module.exports : Symbol(Sub, Decl(index.js, 7, 1)) +>module : Symbol(module, Decl(index.js, 0, 0), Decl(index.js, 10, 27)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>Sub : Symbol(Sub, Decl(index.js, 7, 1)) + + constructor() { + this.instance = new module.exports(10); +>this.instance : Symbol(Sub.instance, Decl(index.js, 9, 19)) +>this : Symbol(Sub, Decl(index.js, 8, 20)) +>instance : Symbol(Sub.instance, Decl(index.js, 9, 19)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0), Decl(index.js, 10, 27)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) + } +} + diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.types b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.types new file mode 100644 index 0000000000000..a4d435e2a9d3a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +module.exports = class { +>module.exports = class { /** * @param {number} p */ constructor(p) { this.t = 12 + p; }} : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>class { /** * @param {number} p */ constructor(p) { this.t = 12 + p; }} : typeof import("tests/cases/conformance/jsdoc/declarations/index") + + /** + * @param {number} p + */ + constructor(p) { +>p : number + + this.t = 12 + p; +>this.t = 12 + p : number +>this.t : number +>this : this +>t : number +>12 + p : number +>12 : 12 +>p : number + } +} +module.exports.Sub = class { +>module.exports.Sub = class { constructor() { this.instance = new module.exports(10); }} : typeof Sub +>module.exports.Sub : typeof Sub +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>Sub : typeof Sub +>class { constructor() { this.instance = new module.exports(10); }} : typeof Sub + + constructor() { + this.instance = new module.exports(10); +>this.instance = new module.exports(10) : import("tests/cases/conformance/jsdoc/declarations/index") +>this.instance : import("tests/cases/conformance/jsdoc/declarations/index") +>this : this +>instance : import("tests/cases/conformance/jsdoc/declarations/index") +>new module.exports(10) : import("tests/cases/conformance/jsdoc/declarations/index") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>10 : 10 + } +} + diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.js b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.js new file mode 100644 index 0000000000000..df093050b7c49 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.js @@ -0,0 +1,86 @@ +//// [index.js] +// TODO: Fixup +class A { + member = new Q(); +} +class Q { + x = 42; +} +module.exports = class Q { + constructor() { + this.x = new A(); + } +} +module.exports.Another = Q; + + +//// [index.js] +// TODO: Fixup +var A = /** @class */ (function () { + function A() { + this.member = new Q(); + } + return A; +}()); +var Q = /** @class */ (function () { + function Q() { + this.x = 42; + } + return Q; +}()); +module.exports = /** @class */ (function () { + function Q() { + this.x = new A(); + } + return Q; +}()); +module.exports.Another = Q; + + +//// [index.d.ts] +export = Q; +declare class Q { + x: A; +} +declare namespace Q { + export { Another }; +} +declare class A { + member: Q; +} +declare var Another: typeof Q; +declare class Q { + x: number; +} + + +//// [DtsFileErrors] + + +out/index.d.ts(2,15): error TS2300: Duplicate identifier 'Q'. +out/index.d.ts(5,19): error TS2300: Duplicate identifier 'Q'. +out/index.d.ts(12,15): error TS2300: Duplicate identifier 'Q'. + + +==== ./out/index.d.ts (3 errors) ==== + export = Q; + declare class Q { + ~ +!!! error TS2300: Duplicate identifier 'Q'. + x: A; + } + declare namespace Q { + ~ +!!! error TS2300: Duplicate identifier 'Q'. + export { Another }; + } + declare class A { + member: Q; + } + declare var Another: typeof Q; + declare class Q { + ~ +!!! error TS2300: Duplicate identifier 'Q'. + x: number; + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.symbols b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.symbols new file mode 100644 index 0000000000000..37f1cf9124daf --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// TODO: Fixup +class A { +>A : Symbol(A, Decl(index.js, 0, 0)) + + member = new Q(); +>member : Symbol(A.member, Decl(index.js, 1, 9)) +>Q : Symbol(Q, Decl(index.js, 3, 1)) +} +class Q { +>Q : Symbol(Q, Decl(index.js, 3, 1)) + + x = 42; +>x : Symbol(Q.x, Decl(index.js, 4, 9)) +} +module.exports = class Q { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 6, 1)) +>exports : Symbol(export=, Decl(index.js, 6, 1)) +>Q : Symbol(Q, Decl(index.js, 7, 16)) + + constructor() { + this.x = new A(); +>this.x : Symbol(Q.x, Decl(index.js, 8, 19)) +>this : Symbol(Q, Decl(index.js, 7, 16)) +>x : Symbol(Q.x, Decl(index.js, 8, 19)) +>A : Symbol(A, Decl(index.js, 0, 0)) + } +} +module.exports.Another = Q; +>module.exports.Another : Symbol(Another) +>module.exports : Symbol(Another, Decl(index.js, 11, 1)) +>module : Symbol(module, Decl(index.js, 6, 1)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>Another : Symbol(Another, Decl(index.js, 11, 1)) +>Q : Symbol(Q, Decl(index.js, 3, 1)) + diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.types b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.types new file mode 100644 index 0000000000000..bd3594e288403 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedClassExpressionShadowing.types @@ -0,0 +1,44 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// TODO: Fixup +class A { +>A : A + + member = new Q(); +>member : Q +>new Q() : Q +>Q : typeof Q +} +class Q { +>Q : Q + + x = 42; +>x : number +>42 : 42 +} +module.exports = class Q { +>module.exports = class Q { constructor() { this.x = new A(); }} : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>class Q { constructor() { this.x = new A(); }} : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>Q : typeof import("tests/cases/conformance/jsdoc/declarations/index") + + constructor() { + this.x = new A(); +>this.x = new A() : A +>this.x : A +>this : this +>x : A +>new A() : A +>A : typeof A + } +} +module.exports.Another = Q; +>module.exports.Another = Q : typeof Q +>module.exports.Another : typeof Q +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>Another : typeof Q +>Q : typeof Q + diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.js b/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.js new file mode 100644 index 0000000000000..c900f28602e57 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.js @@ -0,0 +1,47 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedVisibility.ts] //// + +//// [obj.js] +module.exports = class Obj { + constructor() { + this.x = 12; + } +} +//// [index.js] +const Obj = require("./obj"); + +class Container { + constructor() { + this.usage = new Obj(); + } +} + +module.exports = Container; + +//// [obj.js] +module.exports = /** @class */ (function () { + function Obj() { + this.x = 12; + } + return Obj; +}()); +//// [index.js] +var Obj = require("./obj"); +var Container = /** @class */ (function () { + function Container() { + this.usage = new Obj(); + } + return Container; +}()); +module.exports = Container; + + +//// [obj.d.ts] +export = Obj; +declare class Obj { + x: number; +} +//// [index.d.ts] +export = Container; +declare class Container { + usage: import("./obj"); +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.symbols b/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.symbols new file mode 100644 index 0000000000000..e939df536ffa1 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.symbols @@ -0,0 +1,38 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const Obj = require("./obj"); +>Obj : Symbol(Obj, Decl(index.js, 0, 5)) +>require : Symbol(require) +>"./obj" : Symbol("tests/cases/conformance/jsdoc/declarations/obj", Decl(obj.js, 0, 0)) + +class Container { +>Container : Symbol(Container, Decl(index.js, 0, 29)) + + constructor() { + this.usage = new Obj(); +>this.usage : Symbol(Container.usage, Decl(index.js, 3, 19)) +>this : Symbol(Container, Decl(index.js, 0, 29)) +>usage : Symbol(Container.usage, Decl(index.js, 3, 19)) +>Obj : Symbol(Obj, Decl(index.js, 0, 5)) + } +} + +module.exports = Container; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 6, 1)) +>exports : Symbol(export=, Decl(index.js, 6, 1)) +>Container : Symbol(Container, Decl(index.js, 0, 29)) + +=== tests/cases/conformance/jsdoc/declarations/obj.js === +module.exports = class Obj { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/obj", Decl(obj.js, 0, 0)) +>module : Symbol(export=, Decl(obj.js, 0, 0)) +>exports : Symbol(export=, Decl(obj.js, 0, 0)) +>Obj : Symbol(Obj, Decl(obj.js, 0, 16)) + + constructor() { + this.x = 12; +>this.x : Symbol(Obj.x, Decl(obj.js, 1, 19)) +>this : Symbol(Obj, Decl(obj.js, 0, 16)) +>x : Symbol(Obj.x, Decl(obj.js, 1, 19)) + } +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.types b/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.types new file mode 100644 index 0000000000000..6398c9bada02a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignedVisibility.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const Obj = require("./obj"); +>Obj : typeof import("tests/cases/conformance/jsdoc/declarations/obj") +>require("./obj") : typeof import("tests/cases/conformance/jsdoc/declarations/obj") +>require : any +>"./obj" : "./obj" + +class Container { +>Container : Container + + constructor() { + this.usage = new Obj(); +>this.usage = new Obj() : import("tests/cases/conformance/jsdoc/declarations/obj") +>this.usage : import("tests/cases/conformance/jsdoc/declarations/obj") +>this : this +>usage : import("tests/cases/conformance/jsdoc/declarations/obj") +>new Obj() : import("tests/cases/conformance/jsdoc/declarations/obj") +>Obj : typeof import("tests/cases/conformance/jsdoc/declarations/obj") + } +} + +module.exports = Container; +>module.exports = Container : typeof Container +>module.exports : typeof Container +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof Container; } +>exports : typeof Container +>Container : typeof Container + +=== tests/cases/conformance/jsdoc/declarations/obj.js === +module.exports = class Obj { +>module.exports = class Obj { constructor() { this.x = 12; }} : typeof import("tests/cases/conformance/jsdoc/declarations/obj") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/obj") +>module : { "tests/cases/conformance/jsdoc/declarations/obj": typeof import("tests/cases/conformance/jsdoc/declarations/obj"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/obj") +>class Obj { constructor() { this.x = 12; }} : typeof import("tests/cases/conformance/jsdoc/declarations/obj") +>Obj : typeof import("tests/cases/conformance/jsdoc/declarations/obj") + + constructor() { + this.x = 12; +>this.x = 12 : 12 +>this.x : number +>this : this +>x : number +>12 : 12 + } +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.js b/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.js new file mode 100644 index 0000000000000..54bc1f49bb2f2 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.js @@ -0,0 +1,40 @@ +//// [index.js] +const Strings = { + a: "A", + b: "B" +}; +module.exports = { + thing: "ok", + also: "ok", + desc: { + item: "ok" + } +}; +module.exports.Strings = Strings; + + +//// [index.js] +var Strings = { + a: "A", + b: "B" +}; +module.exports = { + thing: "ok", + also: "ok", + desc: { + item: "ok" + } +}; +module.exports.Strings = Strings; + + +//// [index.d.ts] +export namespace Strings { + export const a: string; + export const b: string; +} +export declare const thing: string; +export declare const also: string; +export declare namespace desc { + export const item: string; +} diff --git a/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.symbols b/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.symbols new file mode 100644 index 0000000000000..4d79913433181 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const Strings = { +>Strings : Symbol(Strings, Decl(index.js, 0, 5)) + + a: "A", +>a : Symbol(a, Decl(index.js, 0, 17)) + + b: "B" +>b : Symbol(b, Decl(index.js, 1, 11)) + +}; +module.exports = { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 3, 2)) +>exports : Symbol(export=, Decl(index.js, 3, 2)) + + thing: "ok", +>thing : Symbol(thing, Decl(index.js, 4, 18)) + + also: "ok", +>also : Symbol(also, Decl(index.js, 5, 16)) + + desc: { +>desc : Symbol(desc, Decl(index.js, 6, 15)) + + item: "ok" +>item : Symbol(item, Decl(index.js, 7, 11)) + } +}; +module.exports.Strings = Strings; +>module.exports.Strings : Symbol(Strings, Decl(index.js, 10, 2)) +>module.exports : Symbol(Strings, Decl(index.js, 10, 2)) +>module : Symbol(module, Decl(index.js, 3, 2)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>Strings : Symbol(Strings, Decl(index.js, 10, 2)) +>Strings : Symbol(Strings, Decl(index.js, 0, 5)) + diff --git a/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.types b/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.types new file mode 100644 index 0000000000000..2b7bd15ac9fdb --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignmentExpressionPlusSecondary.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const Strings = { +>Strings : { a: string; b: string; } +>{ a: "A", b: "B"} : { a: string; b: string; } + + a: "A", +>a : string +>"A" : "A" + + b: "B" +>b : string +>"B" : "B" + +}; +module.exports = { +>module.exports = { thing: "ok", also: "ok", desc: { item: "ok" }} : { thing: string; also: string; desc: { item: string; }; Strings: { a: string; b: string; }; } +>module.exports : { thing: string; also: string; desc: { item: string; }; Strings: { a: string; b: string; }; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { thing: string; also: string; desc: { item: string; }; Strings: { a: string; b: string; }; }; } +>exports : { thing: string; also: string; desc: { item: string; }; Strings: { a: string; b: string; }; } +>{ thing: "ok", also: "ok", desc: { item: "ok" }} : { thing: string; also: string; desc: { item: string; }; } + + thing: "ok", +>thing : string +>"ok" : "ok" + + also: "ok", +>also : string +>"ok" : "ok" + + desc: { +>desc : { item: string; } +>{ item: "ok" } : { item: string; } + + item: "ok" +>item : string +>"ok" : "ok" + } +}; +module.exports.Strings = Strings; +>module.exports.Strings = Strings : { a: string; b: string; } +>module.exports.Strings : { a: string; b: string; } +>module.exports : { thing: string; also: string; desc: { item: string; }; Strings: { a: string; b: string; }; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { thing: string; also: string; desc: { item: string; }; Strings: { a: string; b: string; }; }; } +>exports : { thing: string; also: string; desc: { item: string; }; Strings: { a: string; b: string; }; } +>Strings : { a: string; b: string; } +>Strings : { a: string; b: string; } + diff --git a/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.js b/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.js new file mode 100644 index 0000000000000..04aa01e247e21 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.js @@ -0,0 +1,30 @@ +//// [index.js] +var x = 12; +module.exports = { + extends: 'base', + more: { + others: ['strs'] + }, + x +}; + +//// [index.js] +var x = 12; +module.exports = { + extends: 'base', + more: { + others: ['strs'] + }, + x: x +}; + + +//// [index.d.ts] +declare const _exports: { + extends: string; + more: { + others: string[]; + }; + x: number; +}; +export = _exports; diff --git a/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.symbols b/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.symbols new file mode 100644 index 0000000000000..182a64ba32f7c --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +var x = 12; +>x : Symbol(x, Decl(index.js, 0, 3)) + +module.exports = { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 0, 11)) +>exports : Symbol(export=, Decl(index.js, 0, 11)) + + extends: 'base', +>extends : Symbol(extends, Decl(index.js, 1, 18)) + + more: { +>more : Symbol(more, Decl(index.js, 2, 20)) + + others: ['strs'] +>others : Symbol(others, Decl(index.js, 3, 11)) + + }, + x +>x : Symbol(x, Decl(index.js, 5, 6)) + +}; diff --git a/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.types b/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.types new file mode 100644 index 0000000000000..bd3191805e49d --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportAssignmentWithKeywordName.types @@ -0,0 +1,30 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +var x = 12; +>x : number +>12 : 12 + +module.exports = { +>module.exports = { extends: 'base', more: { others: ['strs'] }, x} : { extends: string; more: { others: string[]; }; x: number; } +>module.exports : { extends: string; more: { others: string[]; }; x: number; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { extends: string; more: { others: string[]; }; x: number; }; } +>exports : { extends: string; more: { others: string[]; }; x: number; } +>{ extends: 'base', more: { others: ['strs'] }, x} : { extends: string; more: { others: string[]; }; x: number; } + + extends: 'base', +>extends : string +>'base' : "base" + + more: { +>more : { others: string[]; } +>{ others: ['strs'] } : { others: string[]; } + + others: ['strs'] +>others : string[] +>['strs'] : string[] +>'strs' : "strs" + + }, + x +>x : number + +}; diff --git a/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.js b/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.js new file mode 100644 index 0000000000000..cac7cda56c549 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.js @@ -0,0 +1,165 @@ +//// [index.js] +Object.defineProperty(module.exports, "a", { value: function a() {} }); + +Object.defineProperty(module.exports, "b", { value: function b() {} }); +Object.defineProperty(module.exports.b, "cat", { value: "cat" }); + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +function d(a, b) { return /** @type {*} */(null); } +Object.defineProperty(module.exports, "d", { value: d }); + + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +function e(a, b) { return /** @type {*} */(null); } +Object.defineProperty(module.exports, "e", { value: e }); + +/** + * @template T + * @param {T} a + */ +function f(a) { + return a; +} +Object.defineProperty(module.exports, "f", { value: f }); +Object.defineProperty(module.exports.f, "self", { value: module.exports.f }); + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { + return a.x && b.y(); +} +Object.defineProperty(module.exports, "g", { value: g }); + + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} +Object.defineProperty(module.exports, "h", { value: hh }); + +Object.defineProperty(module.exports, "i", { value: function i(){} }); +Object.defineProperty(module.exports, "ii", { value: module.exports.i }); + +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +Object.defineProperty(module.exports, "jj", { value: module.exports.j }); +Object.defineProperty(module.exports, "j", { value: function j() {} }); + + +//// [index.js] +Object.defineProperty(module.exports, "a", { value: function a() { } }); +Object.defineProperty(module.exports, "b", { value: function b() { } }); +Object.defineProperty(module.exports.b, "cat", { value: "cat" }); +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +function d(a, b) { return /** @type {*} */ (null); } +Object.defineProperty(module.exports, "d", { value: d }); +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +function e(a, b) { return /** @type {*} */ (null); } +Object.defineProperty(module.exports, "e", { value: e }); +/** + * @template T + * @param {T} a + */ +function f(a) { + return a; +} +Object.defineProperty(module.exports, "f", { value: f }); +Object.defineProperty(module.exports.f, "self", { value: module.exports.f }); +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { + return a.x && b.y(); +} +Object.defineProperty(module.exports, "g", { value: g }); +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} +Object.defineProperty(module.exports, "h", { value: hh }); +Object.defineProperty(module.exports, "i", { value: function i() { } }); +Object.defineProperty(module.exports, "ii", { value: module.exports.i }); +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +Object.defineProperty(module.exports, "jj", { value: module.exports.j }); +Object.defineProperty(module.exports, "j", { value: function j() { } }); + + +//// [index.d.ts] +export function a(): void; +export function b(): void; +export namespace b { + export const cat: string; +} +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +export function d(a: number, b: number): string; +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +export function e(a: T, b: U): T & U; +/** + * @template T + * @param {T} a + */ +export function f(a: T): T; +export namespace f { + /** + * @template T + * @param {T} a + */ + export function self(a: T): T; +} +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +export function g(a: { + x: string; +}, b: { + y: () => void; +}): void; +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +export function h(a: { + x: string; +}, b: { + y: () => void; +}): void; +export function i(): void; +export function ii(): void; +export function jj(): void; +export function j(): void; diff --git a/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.symbols b/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.symbols new file mode 100644 index 0000000000000..03cf1ce41b5e0 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.symbols @@ -0,0 +1,228 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +Object.defineProperty(module.exports, "a", { value: function a() {} }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"a" : Symbol(a, Decl(index.js, 0, 0)) +>value : Symbol(value, Decl(index.js, 0, 44)) +>a : Symbol(a, Decl(index.js, 0, 51)) + +Object.defineProperty(module.exports, "b", { value: function b() {} }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"b" : Symbol(b, Decl(index.js, 0, 71), Decl(index.js, 3, 37)) +>value : Symbol(value, Decl(index.js, 2, 44)) +>b : Symbol(b, Decl(index.js, 2, 51)) + +Object.defineProperty(module.exports.b, "cat", { value: "cat" }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports.b : Symbol(b, Decl(index.js, 0, 71), Decl(index.js, 3, 37)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>b : Symbol(b, Decl(index.js, 0, 71), Decl(index.js, 3, 37)) +>"cat" : Symbol(b.cat, Decl(index.js, 2, 71)) +>value : Symbol(value, Decl(index.js, 3, 48)) + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +function d(a, b) { return /** @type {*} */(null); } +>d : Symbol(d, Decl(index.js, 3, 65)) +>a : Symbol(a, Decl(index.js, 10, 11)) +>b : Symbol(b, Decl(index.js, 10, 13)) + +Object.defineProperty(module.exports, "d", { value: d }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"d" : Symbol(d, Decl(index.js, 10, 51)) +>value : Symbol(value, Decl(index.js, 11, 44)) +>d : Symbol(d, Decl(index.js, 3, 65)) + + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +function e(a, b) { return /** @type {*} */(null); } +>e : Symbol(e, Decl(index.js, 11, 57)) +>a : Symbol(a, Decl(index.js, 20, 11)) +>b : Symbol(b, Decl(index.js, 20, 13)) + +Object.defineProperty(module.exports, "e", { value: e }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"e" : Symbol(e, Decl(index.js, 20, 51)) +>value : Symbol(value, Decl(index.js, 21, 44)) +>e : Symbol(e, Decl(index.js, 11, 57)) + +/** + * @template T + * @param {T} a + */ +function f(a) { +>f : Symbol(f, Decl(index.js, 21, 57)) +>a : Symbol(a, Decl(index.js, 27, 11)) + + return a; +>a : Symbol(a, Decl(index.js, 27, 11)) +} +Object.defineProperty(module.exports, "f", { value: f }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"f" : Symbol(f, Decl(index.js, 29, 1), Decl(index.js, 31, 37)) +>value : Symbol(value, Decl(index.js, 30, 44)) +>f : Symbol(f, Decl(index.js, 21, 57)) + +Object.defineProperty(module.exports.f, "self", { value: module.exports.f }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports.f : Symbol(f, Decl(index.js, 29, 1), Decl(index.js, 31, 37)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>f : Symbol(f, Decl(index.js, 29, 1), Decl(index.js, 31, 37)) +>"self" : Symbol(f.self, Decl(index.js, 30, 57)) +>value : Symbol(value, Decl(index.js, 31, 49)) +>module.exports.f : Symbol(f, Decl(index.js, 29, 1), Decl(index.js, 31, 37)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>f : Symbol(f, Decl(index.js, 29, 1), Decl(index.js, 31, 37)) + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { +>g : Symbol(g, Decl(index.js, 31, 77)) +>a : Symbol(a, Decl(index.js, 37, 11)) +>b : Symbol(b, Decl(index.js, 37, 13)) + + return a.x && b.y(); +>a.x : Symbol(x, Decl(index.js, 34, 12)) +>a : Symbol(a, Decl(index.js, 37, 11)) +>x : Symbol(x, Decl(index.js, 34, 12)) +>b.y : Symbol(y, Decl(index.js, 35, 12)) +>b : Symbol(b, Decl(index.js, 37, 13)) +>y : Symbol(y, Decl(index.js, 35, 12)) +} +Object.defineProperty(module.exports, "g", { value: g }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"g" : Symbol(g, Decl(index.js, 39, 1)) +>value : Symbol(value, Decl(index.js, 40, 44)) +>g : Symbol(g, Decl(index.js, 31, 77)) + + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { +>hh : Symbol(hh, Decl(index.js, 40, 57)) +>a : Symbol(a, Decl(index.js, 47, 12)) +>b : Symbol(b, Decl(index.js, 47, 14)) + + return a.x && b.y(); +>a.x : Symbol(x, Decl(index.js, 44, 12)) +>a : Symbol(a, Decl(index.js, 47, 12)) +>x : Symbol(x, Decl(index.js, 44, 12)) +>b.y : Symbol(y, Decl(index.js, 45, 12)) +>b : Symbol(b, Decl(index.js, 47, 14)) +>y : Symbol(y, Decl(index.js, 45, 12)) +} +Object.defineProperty(module.exports, "h", { value: hh }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"h" : Symbol(h, Decl(index.js, 49, 1)) +>value : Symbol(value, Decl(index.js, 50, 44)) +>hh : Symbol(hh, Decl(index.js, 40, 57)) + +Object.defineProperty(module.exports, "i", { value: function i(){} }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"i" : Symbol(i, Decl(index.js, 50, 58)) +>value : Symbol(value, Decl(index.js, 52, 44)) +>i : Symbol(i, Decl(index.js, 52, 51)) + +Object.defineProperty(module.exports, "ii", { value: module.exports.i }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"ii" : Symbol(ii, Decl(index.js, 52, 70)) +>value : Symbol(value, Decl(index.js, 53, 45)) +>module.exports.i : Symbol(i, Decl(index.js, 50, 58)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>i : Symbol(i, Decl(index.js, 50, 58)) + +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +Object.defineProperty(module.exports, "jj", { value: module.exports.j }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"jj" : Symbol(jj, Decl(index.js, 53, 73)) +>value : Symbol(value, Decl(index.js, 56, 45)) +>module.exports.j : Symbol(j, Decl(index.js, 56, 73)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>j : Symbol(j, Decl(index.js, 56, 73)) + +Object.defineProperty(module.exports, "j", { value: function j() {} }); +>Object.defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>defineProperty : Symbol(ObjectConstructor.defineProperty, Decl(lib.es5.d.ts, --, --)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 22), Decl(index.js, 31, 56), Decl(index.js, 53, 52), Decl(index.js, 56, 52)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>"j" : Symbol(j, Decl(index.js, 56, 73)) +>value : Symbol(value, Decl(index.js, 57, 44)) +>j : Symbol(j, Decl(index.js, 57, 51)) + diff --git a/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.types b/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.types new file mode 100644 index 0000000000000..c8cf0b47995b8 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportDefinePropertyEmit.types @@ -0,0 +1,267 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +Object.defineProperty(module.exports, "a", { value: function a() {} }); +>Object.defineProperty(module.exports, "a", { value: function a() {} }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"a" : "a" +>{ value: function a() {} } : { value: () => void; } +>value : () => void +>function a() {} : () => void +>a : () => void + +Object.defineProperty(module.exports, "b", { value: function b() {} }); +>Object.defineProperty(module.exports, "b", { value: function b() {} }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"b" : "b" +>{ value: function b() {} } : { value: () => void; } +>value : () => void +>function b() {} : () => void +>b : () => void + +Object.defineProperty(module.exports.b, "cat", { value: "cat" }); +>Object.defineProperty(module.exports.b, "cat", { value: "cat" }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports.b : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>b : () => void +>"cat" : "cat" +>{ value: "cat" } : { value: string; } +>value : string +>"cat" : "cat" + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +function d(a, b) { return /** @type {*} */(null); } +>d : (a: number, b: number) => string +>a : number +>b : number +>(null) : any +>null : null + +Object.defineProperty(module.exports, "d", { value: d }); +>Object.defineProperty(module.exports, "d", { value: d }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"d" : "d" +>{ value: d } : { value: (a: number, b: number) => string; } +>value : (a: number, b: number) => string +>d : (a: number, b: number) => string + + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +function e(a, b) { return /** @type {*} */(null); } +>e : (a: T, b: U) => T & U +>a : T +>b : U +>(null) : any +>null : null + +Object.defineProperty(module.exports, "e", { value: e }); +>Object.defineProperty(module.exports, "e", { value: e }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"e" : "e" +>{ value: e } : { value: (a: T, b: U) => T & U; } +>value : (a: T, b: U) => T & U +>e : (a: T, b: U) => T & U + +/** + * @template T + * @param {T} a + */ +function f(a) { +>f : (a: T) => T +>a : T + + return a; +>a : T +} +Object.defineProperty(module.exports, "f", { value: f }); +>Object.defineProperty(module.exports, "f", { value: f }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"f" : "f" +>{ value: f } : { value: (a: T) => T; } +>value : (a: T) => T +>f : (a: T) => T + +Object.defineProperty(module.exports.f, "self", { value: module.exports.f }); +>Object.defineProperty(module.exports.f, "self", { value: module.exports.f }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports.f : (a: T) => T +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>f : (a: T) => T +>"self" : "self" +>{ value: module.exports.f } : { value: (a: T) => T; } +>value : (a: T) => T +>module.exports.f : (a: T) => T +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>f : (a: T) => T + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { +>g : (a: { x: string; }, b: { y: () => void; }) => void +>a : { x: string; } +>b : { y: () => void; } + + return a.x && b.y(); +>a.x && b.y() : void +>a.x : string +>a : { x: string; } +>x : string +>b.y() : void +>b.y : () => void +>b : { y: () => void; } +>y : () => void +} +Object.defineProperty(module.exports, "g", { value: g }); +>Object.defineProperty(module.exports, "g", { value: g }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"g" : "g" +>{ value: g } : { value: (a: { x: string; }, b: { y: () => void; }) => void; } +>value : (a: { x: string; }, b: { y: () => void; }) => void +>g : (a: { x: string; }, b: { y: () => void; }) => void + + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { +>hh : (a: { x: string; }, b: { y: () => void; }) => void +>a : { x: string; } +>b : { y: () => void; } + + return a.x && b.y(); +>a.x && b.y() : void +>a.x : string +>a : { x: string; } +>x : string +>b.y() : void +>b.y : () => void +>b : { y: () => void; } +>y : () => void +} +Object.defineProperty(module.exports, "h", { value: hh }); +>Object.defineProperty(module.exports, "h", { value: hh }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"h" : "h" +>{ value: hh } : { value: (a: { x: string; }, b: { y: () => void; }) => void; } +>value : (a: { x: string; }, b: { y: () => void; }) => void +>hh : (a: { x: string; }, b: { y: () => void; }) => void + +Object.defineProperty(module.exports, "i", { value: function i(){} }); +>Object.defineProperty(module.exports, "i", { value: function i(){} }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"i" : "i" +>{ value: function i(){} } : { value: () => void; } +>value : () => void +>function i(){} : () => void +>i : () => void + +Object.defineProperty(module.exports, "ii", { value: module.exports.i }); +>Object.defineProperty(module.exports, "ii", { value: module.exports.i }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"ii" : "ii" +>{ value: module.exports.i } : { value: () => void; } +>value : () => void +>module.exports.i : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>i : () => void + +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +Object.defineProperty(module.exports, "jj", { value: module.exports.j }); +>Object.defineProperty(module.exports, "jj", { value: module.exports.j }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"jj" : "jj" +>{ value: module.exports.j } : { value: () => void; } +>value : () => void +>module.exports.j : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>j : () => void + +Object.defineProperty(module.exports, "j", { value: function j() {} }); +>Object.defineProperty(module.exports, "j", { value: function j() {} }) : any +>Object.defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>Object : ObjectConstructor +>defineProperty : (o: any, p: string | number | symbol, attributes: PropertyDescriptor & ThisType) => any +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>"j" : "j" +>{ value: function j() {} } : { value: () => void; } +>value : () => void +>function j() {} : () => void +>j : () => void + diff --git a/tests/baselines/reference/jsDeclarationsExportForms.js b/tests/baselines/reference/jsDeclarationsExportForms.js new file mode 100644 index 0000000000000..b94a07eb3fd06 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportForms.js @@ -0,0 +1,169 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportForms.ts] //// + +//// [cls.js] +export class Foo {} + +//// [func.js] +export function func() {} + +//// [bar.js] +export * from "./cls"; + +//// [bar2.js] +export * from "./func"; +export * from "./cls"; + +//// [baz.js] +import {Foo} from "./cls"; +export {Foo}; + +//// [bat.js] +import * as ns from "./cls"; +export default ns; + +//// [ban.js] +import * as ns from "./cls"; +export {ns}; + +//// [bol.js] +import * as ns from "./cls"; +export { ns as classContainer }; + +//// [cjs.js] +const ns = require("./cls"); +module.exports = { ns }; + +//// [cjs2.js] +const ns = require("./cls"); +module.exports = ns; + +//// [cjs3.js] +const ns = require("./cls"); +module.exports.ns = ns; + +//// [cjs4.js] +const ns = require("./cls"); +module.exports.names = ns; + +//// [includeAll.js] +import "./cjs4"; +import "./cjs3"; +import "./cjs2"; +import "./cjs"; +import "./bol"; +import "./ban"; +import "./bat"; +import "./baz"; +import "./bar"; +import "./bar2"; + + +//// [cls.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +exports.Foo = Foo; +//// [func.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function func() { } +exports.func = func; +//// [bar.js] +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +Object.defineProperty(exports, "__esModule", { value: true }); +__export(require("./cls")); +//// [bar2.js] +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +Object.defineProperty(exports, "__esModule", { value: true }); +__export(require("./func")); +__export(require("./cls")); +//// [baz.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var cls_1 = require("./cls"); +exports.Foo = cls_1.Foo; +//// [bat.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var ns = require("./cls"); +exports.default = ns; +//// [ban.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var ns = require("./cls"); +exports.ns = ns; +//// [bol.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var ns = require("./cls"); +exports.classContainer = ns; +//// [cjs.js] +var ns = require("./cls"); +module.exports = { ns: ns }; +//// [cjs2.js] +var ns = require("./cls"); +module.exports = ns; +//// [cjs3.js] +var ns = require("./cls"); +module.exports.ns = ns; +//// [cjs4.js] +var ns = require("./cls"); +module.exports.names = ns; +//// [includeAll.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +require("./cjs4"); +require("./cjs3"); +require("./cjs2"); +require("./cjs"); +require("./bol"); +require("./ban"); +require("./bat"); +require("./baz"); +require("./bar"); +require("./bar2"); + + +//// [cls.d.ts] +export class Foo { +} +//// [func.d.ts] +export function func(): void; +//// [bar.d.ts] +export * from "./cls"; +//// [bar2.d.ts] +export * from "./func"; +export * from "./cls"; +//// [baz.d.ts] +export { Foo }; +import { Foo } from "./cls"; +//// [bat.d.ts] +export default ns; +import * as ns from "./cls"; +//// [ban.d.ts] +export { ns }; +import * as ns from "./cls"; +//// [bol.d.ts] +export { ns as classContainer }; +import * as ns from "./cls"; +//// [cjs.d.ts] +export const ns: typeof import("./cls"); +//// [cjs2.d.ts] +export = ns; +declare const ns: typeof import("./cls"); +//// [cjs3.d.ts] +export var ns: typeof import("./cls"); +//// [cjs4.d.ts] +export var names: typeof import("./cls"); +//// [includeAll.d.ts] +export {}; diff --git a/tests/baselines/reference/jsDeclarationsExportForms.symbols b/tests/baselines/reference/jsDeclarationsExportForms.symbols new file mode 100644 index 0000000000000..300425b5c96e9 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportForms.symbols @@ -0,0 +1,109 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +export class Foo {} +>Foo : Symbol(Foo, Decl(cls.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/func.js === +export function func() {} +>func : Symbol(func, Decl(func.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/bar.js === +export * from "./cls"; +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/bar2.js === +export * from "./func"; +No type information for this code.export * from "./cls"; +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/baz.js === +import {Foo} from "./cls"; +>Foo : Symbol(Foo, Decl(baz.js, 0, 8)) + +export {Foo}; +>Foo : Symbol(Foo, Decl(baz.js, 1, 8)) + +=== tests/cases/conformance/jsdoc/declarations/bat.js === +import * as ns from "./cls"; +>ns : Symbol(ns, Decl(bat.js, 0, 6)) + +export default ns; +>ns : Symbol(ns, Decl(bat.js, 0, 6)) + +=== tests/cases/conformance/jsdoc/declarations/ban.js === +import * as ns from "./cls"; +>ns : Symbol(ns, Decl(ban.js, 0, 6)) + +export {ns}; +>ns : Symbol(ns, Decl(ban.js, 1, 8)) + +=== tests/cases/conformance/jsdoc/declarations/bol.js === +import * as ns from "./cls"; +>ns : Symbol(ns, Decl(bol.js, 0, 6)) + +export { ns as classContainer }; +>ns : Symbol(ns, Decl(bol.js, 0, 6)) +>classContainer : Symbol(classContainer, Decl(bol.js, 1, 8)) + +=== tests/cases/conformance/jsdoc/declarations/cjs.js === +const ns = require("./cls"); +>ns : Symbol(ns, Decl(cjs.js, 0, 5)) +>require : Symbol(require) +>"./cls" : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) + +module.exports = { ns }; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/cjs", Decl(cjs.js, 0, 0)) +>module : Symbol(export=, Decl(cjs.js, 0, 28)) +>exports : Symbol(export=, Decl(cjs.js, 0, 28)) +>ns : Symbol(ns, Decl(cjs.js, 1, 18)) + +=== tests/cases/conformance/jsdoc/declarations/cjs2.js === +const ns = require("./cls"); +>ns : Symbol(ns, Decl(cjs2.js, 0, 5)) +>require : Symbol(require) +>"./cls" : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) + +module.exports = ns; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/cjs2", Decl(cjs2.js, 0, 0)) +>module : Symbol(export=, Decl(cjs2.js, 0, 28)) +>exports : Symbol(export=, Decl(cjs2.js, 0, 28)) +>ns : Symbol(ns, Decl(cjs2.js, 0, 5)) + +=== tests/cases/conformance/jsdoc/declarations/cjs3.js === +const ns = require("./cls"); +>ns : Symbol(ns, Decl(cjs3.js, 0, 5)) +>require : Symbol(require) +>"./cls" : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) + +module.exports.ns = ns; +>module.exports.ns : Symbol(ns, Decl(cjs3.js, 0, 28)) +>module.exports : Symbol(ns, Decl(cjs3.js, 0, 28)) +>module : Symbol(module, Decl(cjs3.js, 0, 28)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/cjs3", Decl(cjs3.js, 0, 0)) +>ns : Symbol(ns, Decl(cjs3.js, 0, 28)) +>ns : Symbol(ns, Decl(cjs3.js, 0, 5)) + +=== tests/cases/conformance/jsdoc/declarations/cjs4.js === +const ns = require("./cls"); +>ns : Symbol(ns, Decl(cjs4.js, 0, 5)) +>require : Symbol(require) +>"./cls" : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) + +module.exports.names = ns; +>module.exports.names : Symbol(names, Decl(cjs4.js, 0, 28)) +>module.exports : Symbol(names, Decl(cjs4.js, 0, 28)) +>module : Symbol(module, Decl(cjs4.js, 0, 28)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/cjs4", Decl(cjs4.js, 0, 0)) +>names : Symbol(names, Decl(cjs4.js, 0, 28)) +>ns : Symbol(ns, Decl(cjs4.js, 0, 5)) + +=== tests/cases/conformance/jsdoc/declarations/includeAll.js === +import "./cjs4"; +No type information for this code.import "./cjs3"; +No type information for this code.import "./cjs2"; +No type information for this code.import "./cjs"; +No type information for this code.import "./bol"; +No type information for this code.import "./ban"; +No type information for this code.import "./bat"; +No type information for this code.import "./baz"; +No type information for this code.import "./bar"; +No type information for this code.import "./bar2"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsExportForms.types b/tests/baselines/reference/jsDeclarationsExportForms.types new file mode 100644 index 0000000000000..5f454ee97bf32 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportForms.types @@ -0,0 +1,118 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +export class Foo {} +>Foo : Foo + +=== tests/cases/conformance/jsdoc/declarations/func.js === +export function func() {} +>func : () => void + +=== tests/cases/conformance/jsdoc/declarations/bar.js === +export * from "./cls"; +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/bar2.js === +export * from "./func"; +No type information for this code.export * from "./cls"; +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/baz.js === +import {Foo} from "./cls"; +>Foo : typeof Foo + +export {Foo}; +>Foo : typeof Foo + +=== tests/cases/conformance/jsdoc/declarations/bat.js === +import * as ns from "./cls"; +>ns : typeof ns + +export default ns; +>ns : typeof ns + +=== tests/cases/conformance/jsdoc/declarations/ban.js === +import * as ns from "./cls"; +>ns : typeof ns + +export {ns}; +>ns : typeof ns + +=== tests/cases/conformance/jsdoc/declarations/bol.js === +import * as ns from "./cls"; +>ns : typeof ns + +export { ns as classContainer }; +>ns : typeof ns +>classContainer : typeof ns + +=== tests/cases/conformance/jsdoc/declarations/cjs.js === +const ns = require("./cls"); +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>require("./cls") : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>require : any +>"./cls" : "./cls" + +module.exports = { ns }; +>module.exports = { ns } : { ns: typeof import("tests/cases/conformance/jsdoc/declarations/cls"); } +>module.exports : { ns: typeof import("tests/cases/conformance/jsdoc/declarations/cls"); } +>module : { "tests/cases/conformance/jsdoc/declarations/cjs": { ns: typeof import("tests/cases/conformance/jsdoc/declarations/cls"); }; } +>exports : { ns: typeof import("tests/cases/conformance/jsdoc/declarations/cls"); } +>{ ns } : { ns: typeof import("tests/cases/conformance/jsdoc/declarations/cls"); } +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") + +=== tests/cases/conformance/jsdoc/declarations/cjs2.js === +const ns = require("./cls"); +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>require("./cls") : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>require : any +>"./cls" : "./cls" + +module.exports = ns; +>module.exports = ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>module : { "tests/cases/conformance/jsdoc/declarations/cjs2": typeof import("tests/cases/conformance/jsdoc/declarations/cls"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") + +=== tests/cases/conformance/jsdoc/declarations/cjs3.js === +const ns = require("./cls"); +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>require("./cls") : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>require : any +>"./cls" : "./cls" + +module.exports.ns = ns; +>module.exports.ns = ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>module.exports.ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/cjs3") +>module : { "tests/cases/conformance/jsdoc/declarations/cjs3": typeof import("tests/cases/conformance/jsdoc/declarations/cjs3"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/cjs3") +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") + +=== tests/cases/conformance/jsdoc/declarations/cjs4.js === +const ns = require("./cls"); +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>require("./cls") : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>require : any +>"./cls" : "./cls" + +module.exports.names = ns; +>module.exports.names = ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>module.exports.names : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/cjs4") +>module : { "tests/cases/conformance/jsdoc/declarations/cjs4": typeof import("tests/cases/conformance/jsdoc/declarations/cjs4"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/cjs4") +>names : typeof import("tests/cases/conformance/jsdoc/declarations/cls") +>ns : typeof import("tests/cases/conformance/jsdoc/declarations/cls") + +=== tests/cases/conformance/jsdoc/declarations/includeAll.js === +import "./cjs4"; +No type information for this code.import "./cjs3"; +No type information for this code.import "./cjs2"; +No type information for this code.import "./cjs"; +No type information for this code.import "./bol"; +No type information for this code.import "./ban"; +No type information for this code.import "./bat"; +No type information for this code.import "./baz"; +No type information for this code.import "./bar"; +No type information for this code.import "./bar2"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsExportFormsErr.errors.txt b/tests/baselines/reference/jsDeclarationsExportFormsErr.errors.txt new file mode 100644 index 0000000000000..d0d5c78f0d1af --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportFormsErr.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/jsdoc/declarations/bar.js(1,1): error TS8002: 'import ... =' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/bar.js(2,1): error TS8003: 'export=' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/bin.js(2,1): error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. +tests/cases/conformance/jsdoc/declarations/globalNs.js(2,1): error TS1315: Global module exports may only appear in declaration files. + + +==== tests/cases/conformance/jsdoc/declarations/cls.js (0 errors) ==== + export class Foo {} + +==== tests/cases/conformance/jsdoc/declarations/bar.js (2 errors) ==== + import ns = require("./cls"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS8002: 'import ... =' can only be used in a .ts file. + export = ns; // TS Only + ~~~~~~~~~~~~ +!!! error TS8003: 'export=' can only be used in a .ts file. + +==== tests/cases/conformance/jsdoc/declarations/bin.js (1 errors) ==== + import * as ns from "./cls"; + module.exports = ns; // We refuse to bind cjs module exports assignments in the same file we find an import in + ~~~~~~ +!!! error TS2580: Cannot find name 'module'. Do you need to install type definitions for node? Try `npm i @types/node`. + +==== tests/cases/conformance/jsdoc/declarations/globalNs.js (1 errors) ==== + export * from "./cls"; + export as namespace GLO; // TS Only + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1315: Global module exports may only appear in declaration files. + +==== tests/cases/conformance/jsdoc/declarations/includeAll.js (0 errors) ==== + import "./bar"; + import "./bin"; + import "./globalNs"; + \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsExportFormsErr.js b/tests/baselines/reference/jsDeclarationsExportFormsErr.js new file mode 100644 index 0000000000000..993be331cd520 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportFormsErr.js @@ -0,0 +1,68 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportFormsErr.ts] //// + +//// [cls.js] +export class Foo {} + +//// [bar.js] +import ns = require("./cls"); +export = ns; // TS Only + +//// [bin.js] +import * as ns from "./cls"; +module.exports = ns; // We refuse to bind cjs module exports assignments in the same file we find an import in + +//// [globalNs.js] +export * from "./cls"; +export as namespace GLO; // TS Only + +//// [includeAll.js] +import "./bar"; +import "./bin"; +import "./globalNs"; + + +//// [cls.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +exports.Foo = Foo; +//// [bar.js] +"use strict"; +var ns = require("./cls"); +module.exports = ns; +//// [bin.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var ns = require("./cls"); +module.exports = ns; // We refuse to bind cjs module exports assignments in the same file we find an import in +//// [globalNs.js] +"use strict"; +function __export(m) { + for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; +} +Object.defineProperty(exports, "__esModule", { value: true }); +__export(require("./cls")); +//// [includeAll.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +require("./bar"); +require("./bin"); +require("./globalNs"); + + +//// [cls.d.ts] +export class Foo { +} +//// [bar.d.ts] +export = ns; +import ns = require("./bar"); +//// [bin.d.ts] +export {}; +//// [globalNs.d.ts] +export * from "./cls"; +//// [includeAll.d.ts] +export {}; diff --git a/tests/baselines/reference/jsDeclarationsExportFormsErr.symbols b/tests/baselines/reference/jsDeclarationsExportFormsErr.symbols new file mode 100644 index 0000000000000..a8795f892f26f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportFormsErr.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +export class Foo {} +>Foo : Symbol(Foo, Decl(cls.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/bar.js === +import ns = require("./cls"); +>ns : Symbol(ns, Decl(bar.js, 0, 0)) + +export = ns; // TS Only +>ns : Symbol(ns, Decl(bar.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/bin.js === +import * as ns from "./cls"; +>ns : Symbol(ns, Decl(bin.js, 0, 6)) + +module.exports = ns; // We refuse to bind cjs module exports assignments in the same file we find an import in +>ns : Symbol(ns, Decl(bin.js, 0, 6)) + +=== tests/cases/conformance/jsdoc/declarations/globalNs.js === +export * from "./cls"; +No type information for this code.export as namespace GLO; // TS Only +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/includeAll.js === +import "./bar"; +No type information for this code.import "./bin"; +No type information for this code.import "./globalNs"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsExportFormsErr.types b/tests/baselines/reference/jsDeclarationsExportFormsErr.types new file mode 100644 index 0000000000000..c4035e7ec82db --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportFormsErr.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +export class Foo {} +>Foo : Foo + +=== tests/cases/conformance/jsdoc/declarations/bar.js === +import ns = require("./cls"); +>ns : typeof ns + +export = ns; // TS Only +>ns : typeof ns + +=== tests/cases/conformance/jsdoc/declarations/bin.js === +import * as ns from "./cls"; +>ns : typeof ns + +module.exports = ns; // We refuse to bind cjs module exports assignments in the same file we find an import in +>module.exports = ns : any +>module.exports : any +>module : any +>exports : any +>ns : typeof ns + +=== tests/cases/conformance/jsdoc/declarations/globalNs.js === +export * from "./cls"; +export as namespace GLO; // TS Only +>GLO : any + +=== tests/cases/conformance/jsdoc/declarations/includeAll.js === +import "./bar"; +No type information for this code.import "./bin"; +No type information for this code.import "./globalNs"; +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.js b/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.js new file mode 100644 index 0000000000000..adf1984e5d46a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.js @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportSpecifierNonlocal.ts] //// + +//// [source.js] +export class Thing {} +export class OtherThing {} +//// [index.js] +export { Thing, OtherThing as default } from "./source"; + + +//// [source.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Thing = /** @class */ (function () { + function Thing() { + } + return Thing; +}()); +exports.Thing = Thing; +var OtherThing = /** @class */ (function () { + function OtherThing() { + } + return OtherThing; +}()); +exports.OtherThing = OtherThing; +//// [index.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var source_1 = require("./source"); +exports.Thing = source_1.Thing; +exports.default = source_1.OtherThing; + + +//// [source.d.ts] +export class Thing { +} +export class OtherThing { +} +//// [index.d.ts] +export { Thing, OtherThing as default } from "./source"; diff --git a/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.symbols b/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.symbols new file mode 100644 index 0000000000000..561ebd0e382d0 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/jsdoc/declarations/source.js === +export class Thing {} +>Thing : Symbol(Thing, Decl(source.js, 0, 0)) + +export class OtherThing {} +>OtherThing : Symbol(OtherThing, Decl(source.js, 0, 21)) + +=== tests/cases/conformance/jsdoc/declarations/index.js === +export { Thing, OtherThing as default } from "./source"; +>Thing : Symbol(Thing, Decl(index.js, 0, 8)) +>OtherThing : Symbol(OtherThing, Decl(source.js, 0, 21)) +>default : Symbol(default, Decl(index.js, 0, 15)) + diff --git a/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.types b/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.types new file mode 100644 index 0000000000000..b94684de66536 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportSpecifierNonlocal.types @@ -0,0 +1,13 @@ +=== tests/cases/conformance/jsdoc/declarations/source.js === +export class Thing {} +>Thing : Thing + +export class OtherThing {} +>OtherThing : OtherThing + +=== tests/cases/conformance/jsdoc/declarations/index.js === +export { Thing, OtherThing as default } from "./source"; +>Thing : typeof import("tests/cases/conformance/jsdoc/declarations/source").Thing +>OtherThing : typeof import("tests/cases/conformance/jsdoc/declarations/source").OtherThing +>default : typeof import("tests/cases/conformance/jsdoc/declarations/source").OtherThing + diff --git a/tests/baselines/reference/jsDeclarationsExportSubAssignments.js b/tests/baselines/reference/jsDeclarationsExportSubAssignments.js new file mode 100644 index 0000000000000..3e9ee20f4b67f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportSubAssignments.js @@ -0,0 +1,34 @@ +//// [cls.js] +const Strings = { + a: "A", + b: "B" +}; +class Foo {} +module.exports = Foo; +module.exports.Strings = Strings; + +//// [cls.js] +var Strings = { + a: "A", + b: "B" +}; +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +module.exports = Foo; +module.exports.Strings = Strings; + + +//// [cls.d.ts] +export = Foo; +declare class Foo { +} +declare namespace Foo { + export { Strings }; +} +declare namespace Strings { + export const a: string; + export const b: string; +} diff --git a/tests/baselines/reference/jsDeclarationsExportSubAssignments.symbols b/tests/baselines/reference/jsDeclarationsExportSubAssignments.symbols new file mode 100644 index 0000000000000..a764b8e99d71d --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportSubAssignments.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +const Strings = { +>Strings : Symbol(Strings, Decl(cls.js, 0, 5)) + + a: "A", +>a : Symbol(a, Decl(cls.js, 0, 17)) + + b: "B" +>b : Symbol(b, Decl(cls.js, 1, 11)) + +}; +class Foo {} +>Foo : Symbol(Foo, Decl(cls.js, 3, 2)) + +module.exports = Foo; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) +>module : Symbol(export=, Decl(cls.js, 4, 12)) +>exports : Symbol(export=, Decl(cls.js, 4, 12)) +>Foo : Symbol(Foo, Decl(cls.js, 3, 2)) + +module.exports.Strings = Strings; +>module.exports.Strings : Symbol(Strings) +>module.exports : Symbol(Strings, Decl(cls.js, 5, 21)) +>module : Symbol(module, Decl(cls.js, 4, 12)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) +>Strings : Symbol(Strings, Decl(cls.js, 5, 21)) +>Strings : Symbol(Strings, Decl(cls.js, 0, 5)) + diff --git a/tests/baselines/reference/jsDeclarationsExportSubAssignments.types b/tests/baselines/reference/jsDeclarationsExportSubAssignments.types new file mode 100644 index 0000000000000..765da3557ab05 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsExportSubAssignments.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +const Strings = { +>Strings : { a: string; b: string; } +>{ a: "A", b: "B"} : { a: string; b: string; } + + a: "A", +>a : string +>"A" : "A" + + b: "B" +>b : string +>"B" : "B" + +}; +class Foo {} +>Foo : Foo + +module.exports = Foo; +>module.exports = Foo : typeof Foo +>module.exports : typeof Foo +>module : { "tests/cases/conformance/jsdoc/declarations/cls": typeof Foo; } +>exports : typeof Foo +>Foo : typeof Foo + +module.exports.Strings = Strings; +>module.exports.Strings = Strings : { a: string; b: string; } +>module.exports.Strings : { a: string; b: string; } +>module.exports : typeof Foo +>module : { "tests/cases/conformance/jsdoc/declarations/cls": typeof Foo; } +>exports : typeof Foo +>Strings : { a: string; b: string; } +>Strings : { a: string; b: string; } + diff --git a/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js new file mode 100644 index 0000000000000..f34ad068989ff --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.js @@ -0,0 +1,272 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionClassesCjsExportAssignment.ts] //// + +//// [timer.js] +/** + * @param {number} timeout + */ +function Timer(timeout) { + this.timeout = timeout; +} +module.exports = Timer; +//// [hook.js] +/** + * @typedef {(arg: import("./context")) => void} HookHandler + */ +/** + * @param {HookHandler} handle + */ +function Hook(handle) { + this.handle = handle; +} +module.exports = Hook; + +//// [context.js] +/** + * Imports + * + * @typedef {import("./timer")} Timer + * @typedef {import("./hook")} Hook + * @typedef {import("./hook").HookHandler} HookHandler + */ + +/** + * Input type definition + * + * @typedef {Object} Input + * @prop {Timer} timer + * @prop {Hook} hook + */ + +/** + * State type definition + * + * @typedef {Object} State + * @prop {Timer} timer + * @prop {Hook} hook + */ + +/** + * New `Context` + * + * @class + * @param {Input} input + */ + +function Context(input) { + if (!(this instanceof Context)) { + return new Context(input) + } + this.state = this.construct(input); +} +Context.prototype = { + /** + * @param {Input} input + * @param {HookHandler=} handle + * @returns {State} + */ + construct(input, handle = () => void 0) { + return input; + } +} +module.exports = Context; + + +//// [timer.js] +/** + * @param {number} timeout + */ +function Timer(timeout) { + this.timeout = timeout; +} +module.exports = Timer; +//// [context.js] +/** + * Imports + * + * @typedef {import("./timer")} Timer + * @typedef {import("./hook")} Hook + * @typedef {import("./hook").HookHandler} HookHandler + */ +/** + * Input type definition + * + * @typedef {Object} Input + * @prop {Timer} timer + * @prop {Hook} hook + */ +/** + * State type definition + * + * @typedef {Object} State + * @prop {Timer} timer + * @prop {Hook} hook + */ +/** + * New `Context` + * + * @class + * @param {Input} input + */ +function Context(input) { + if (!(this instanceof Context)) { + return new Context(input); + } + this.state = this.construct(input); +} +Context.prototype = { + /** + * @param {Input} input + * @param {HookHandler=} handle + * @returns {State} + */ + construct: function (input, handle) { + if (handle === void 0) { handle = function () { return void 0; }; } + return input; + } +}; +module.exports = Context; +//// [hook.js] +/** + * @typedef {(arg: import("./context")) => void} HookHandler + */ +/** + * @param {HookHandler} handle + */ +function Hook(handle) { + this.handle = handle; +} +module.exports = Hook; + + +//// [timer.d.ts] +export = Timer; +/** + * @param {number} timeout + */ +declare function Timer(timeout: number): void; +declare class Timer { + /** + * @param {number} timeout + */ + constructor(timeout: number); + timeout: number; +} +//// [context.d.ts] +export = Context; +/** + * Imports + * + * @typedef {import("./timer")} Timer + * @typedef {import("./hook")} Hook + * @typedef {import("./hook").HookHandler} HookHandler + */ +/** + * Input type definition + * + * @typedef {Object} Input + * @prop {Timer} timer + * @prop {Hook} hook + */ +/** + * State type definition + * + * @typedef {Object} State + * @prop {Timer} timer + * @prop {Hook} hook + */ +/** + * New `Context` + * + * @class + * @param {Input} input + */ +declare function Context(input: Input): Context; +declare class Context { + /** + * Imports + * + * @typedef {import("./timer")} Timer + * @typedef {import("./hook")} Hook + * @typedef {import("./hook").HookHandler} HookHandler + */ + /** + * Input type definition + * + * @typedef {Object} Input + * @prop {Timer} timer + * @prop {Hook} hook + */ + /** + * State type definition + * + * @typedef {Object} State + * @prop {Timer} timer + * @prop {Hook} hook + */ + /** + * New `Context` + * + * @class + * @param {Input} input + */ + constructor(input: Input); + state: any; + /** + * @param {Input} input + * @param {HookHandler=} handle + * @returns {State} + */ + construct(input: Input, handle?: (arg: Context) => void): State; +} +declare namespace Context { + export { Timer, Hook, HookHandler, Input, State }; +} +/** + * Input type definition + */ +type Input = { + timer: import("./timer"); + hook: import("./hook"); +}; +/** + * State type definition + */ +type State = { + timer: import("./timer"); + hook: import("./hook"); +}; +/** + * Imports + */ +type Timer = import("./timer"); +/** + * Imports + */ +type Hook = import("./hook"); +/** + * Imports + */ +type HookHandler = (arg: Context) => void; +//// [hook.d.ts] +export = Hook; +/** + * @typedef {(arg: import("./context")) => void} HookHandler + */ +/** + * @param {HookHandler} handle + */ +declare function Hook(handle: (arg: import("./context")) => void): void; +declare class Hook { + /** + * @typedef {(arg: import("./context")) => void} HookHandler + */ + /** + * @param {HookHandler} handle + */ + constructor(handle: (arg: import("./context")) => void); + handle: (arg: import("./context")) => void; +} +declare namespace Hook { + export { HookHandler }; +} +type HookHandler = (arg: import("./context")) => void; diff --git a/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.symbols b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.symbols new file mode 100644 index 0000000000000..a8e34ede3cfc1 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.symbols @@ -0,0 +1,115 @@ +=== tests/cases/conformance/jsdoc/declarations/timer.js === +/** + * @param {number} timeout + */ +function Timer(timeout) { +>Timer : Symbol(Timer, Decl(timer.js, 0, 0)) +>timeout : Symbol(timeout, Decl(timer.js, 3, 15)) + + this.timeout = timeout; +>timeout : Symbol(Timer.timeout, Decl(timer.js, 3, 25)) +>timeout : Symbol(timeout, Decl(timer.js, 3, 15)) +} +module.exports = Timer; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/timer", Decl(timer.js, 0, 0)) +>module : Symbol(export=, Decl(timer.js, 5, 1)) +>exports : Symbol(export=, Decl(timer.js, 5, 1)) +>Timer : Symbol(Timer, Decl(timer.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/hook.js === +/** + * @typedef {(arg: import("./context")) => void} HookHandler + */ +/** + * @param {HookHandler} handle + */ +function Hook(handle) { +>Hook : Symbol(Hook, Decl(hook.js, 0, 0)) +>handle : Symbol(handle, Decl(hook.js, 6, 14)) + + this.handle = handle; +>handle : Symbol(Hook.handle, Decl(hook.js, 6, 23)) +>handle : Symbol(handle, Decl(hook.js, 6, 14)) +} +module.exports = Hook; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/hook", Decl(hook.js, 0, 0)) +>module : Symbol(export=, Decl(hook.js, 8, 1)) +>exports : Symbol(export=, Decl(hook.js, 8, 1)) +>Hook : Symbol(Hook, Decl(hook.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/context.js === +/** + * Imports + * + * @typedef {import("./timer")} Timer + * @typedef {import("./hook")} Hook + * @typedef {import("./hook").HookHandler} HookHandler + */ + +/** + * Input type definition + * + * @typedef {Object} Input + * @prop {Timer} timer + * @prop {Hook} hook + */ + +/** + * State type definition + * + * @typedef {Object} State + * @prop {Timer} timer + * @prop {Hook} hook + */ + +/** + * New `Context` + * + * @class + * @param {Input} input + */ + +function Context(input) { +>Context : Symbol(Context, Decl(context.js, 0, 0), Decl(context.js, 36, 1)) +>input : Symbol(input, Decl(context.js, 31, 17)) + + if (!(this instanceof Context)) { +>this : Symbol(Context, Decl(context.js, 0, 0), Decl(context.js, 36, 1)) +>Context : Symbol(Context, Decl(context.js, 0, 0), Decl(context.js, 36, 1)) + + return new Context(input) +>Context : Symbol(Context, Decl(context.js, 0, 0), Decl(context.js, 36, 1)) +>input : Symbol(input, Decl(context.js, 31, 17)) + } + this.state = this.construct(input); +>this.state : Symbol(Context.state, Decl(context.js, 34, 5)) +>state : Symbol(Context.state, Decl(context.js, 34, 5)) +>this.construct : Symbol(construct, Decl(context.js, 37, 21), Decl(context.js, 37, 21)) +>construct : Symbol(construct, Decl(context.js, 37, 21), Decl(context.js, 37, 21)) +>input : Symbol(input, Decl(context.js, 31, 17)) +} +Context.prototype = { +>Context.prototype : Symbol(Context.prototype, Decl(context.js, 36, 1)) +>Context : Symbol(Context, Decl(context.js, 0, 0), Decl(context.js, 36, 1)) +>prototype : Symbol(Context.prototype, Decl(context.js, 36, 1)) + + /** + * @param {Input} input + * @param {HookHandler=} handle + * @returns {State} + */ + construct(input, handle = () => void 0) { +>construct : Symbol(construct, Decl(context.js, 37, 21)) +>input : Symbol(input, Decl(context.js, 43, 14)) +>handle : Symbol(handle, Decl(context.js, 43, 20)) + + return input; +>input : Symbol(input, Decl(context.js, 43, 14)) + } +} +module.exports = Context; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/context", Decl(context.js, 0, 0)) +>module : Symbol(export=, Decl(context.js, 46, 1)) +>exports : Symbol(export=, Decl(context.js, 46, 1)) +>Context : Symbol(Context, Decl(context.js, 0, 0), Decl(context.js, 36, 1)) + diff --git a/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.types b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.types new file mode 100644 index 0000000000000..f9ee5c6e4c1c0 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionClassesCjsExportAssignment.types @@ -0,0 +1,137 @@ +=== tests/cases/conformance/jsdoc/declarations/timer.js === +/** + * @param {number} timeout + */ +function Timer(timeout) { +>Timer : typeof Timer +>timeout : number + + this.timeout = timeout; +>this.timeout = timeout : number +>this.timeout : any +>this : any +>timeout : any +>timeout : number +} +module.exports = Timer; +>module.exports = Timer : typeof Timer +>module.exports : typeof Timer +>module : { "tests/cases/conformance/jsdoc/declarations/timer": typeof Timer; } +>exports : typeof Timer +>Timer : typeof Timer + +=== tests/cases/conformance/jsdoc/declarations/hook.js === +/** + * @typedef {(arg: import("./context")) => void} HookHandler + */ +/** + * @param {HookHandler} handle + */ +function Hook(handle) { +>Hook : typeof Hook +>handle : (arg: import("tests/cases/conformance/jsdoc/declarations/context")) => void + + this.handle = handle; +>this.handle = handle : (arg: import("tests/cases/conformance/jsdoc/declarations/context")) => void +>this.handle : any +>this : any +>handle : any +>handle : (arg: import("tests/cases/conformance/jsdoc/declarations/context")) => void +} +module.exports = Hook; +>module.exports = Hook : typeof Hook +>module.exports : typeof Hook +>module : { "tests/cases/conformance/jsdoc/declarations/hook": typeof Hook; } +>exports : typeof Hook +>Hook : typeof Hook + +=== tests/cases/conformance/jsdoc/declarations/context.js === +/** + * Imports + * + * @typedef {import("./timer")} Timer + * @typedef {import("./hook")} Hook + * @typedef {import("./hook").HookHandler} HookHandler + */ + +/** + * Input type definition + * + * @typedef {Object} Input + * @prop {Timer} timer + * @prop {Hook} hook + */ + +/** + * State type definition + * + * @typedef {Object} State + * @prop {Timer} timer + * @prop {Hook} hook + */ + +/** + * New `Context` + * + * @class + * @param {Input} input + */ + +function Context(input) { +>Context : typeof Context +>input : Input + + if (!(this instanceof Context)) { +>!(this instanceof Context) : boolean +>(this instanceof Context) : boolean +>this instanceof Context : boolean +>this : this +>Context : typeof Context + + return new Context(input) +>new Context(input) : Context +>Context : typeof Context +>input : Input + } + this.state = this.construct(input); +>this.state = this.construct(input) : State +>this.state : any +>this : this & { construct(input: Input, handle?: (arg: Context) => void): State; } +>state : any +>this.construct(input) : State +>this.construct : (input: Input, handle?: (arg: Context) => void) => State +>this : this & { construct(input: Input, handle?: (arg: Context) => void): State; } +>construct : (input: Input, handle?: (arg: Context) => void) => State +>input : Input +} +Context.prototype = { +>Context.prototype = { /** * @param {Input} input * @param {HookHandler=} handle * @returns {State} */ construct(input, handle = () => void 0) { return input; }} : { construct(input: Input, handle?: (arg: Context) => void): State; } +>Context.prototype : { construct(input: Input, handle?: (arg: Context) => void): State; } +>Context : typeof Context +>prototype : { construct(input: Input, handle?: (arg: Context) => void): State; } +>{ /** * @param {Input} input * @param {HookHandler=} handle * @returns {State} */ construct(input, handle = () => void 0) { return input; }} : { construct(input: Input, handle?: (arg: Context) => void): State; } + + /** + * @param {Input} input + * @param {HookHandler=} handle + * @returns {State} + */ + construct(input, handle = () => void 0) { +>construct : (input: Input, handle?: (arg: Context) => void) => State +>input : Input +>handle : (arg: Context) => void +>() => void 0 : () => any +>void 0 : undefined +>0 : 0 + + return input; +>input : Input + } +} +module.exports = Context; +>module.exports = Context : typeof Context +>module.exports : typeof Context +>module : { "tests/cases/conformance/jsdoc/declarations/context": typeof Context; } +>exports : typeof Context +>Context : typeof Context + diff --git a/tests/baselines/reference/jsDeclarationsFunctionJSDoc.js b/tests/baselines/reference/jsDeclarationsFunctionJSDoc.js new file mode 100644 index 0000000000000..5cb305aa88be2 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionJSDoc.js @@ -0,0 +1,107 @@ +//// [source.js] +/** + * Foos a bar together using an `a` and a `b` + * @param {number} a + * @param {string} b + */ +export function foo(a, b) {} + +/** + * Legacy - DO NOT USE + */ +export class Aleph { + /** + * Impossible to construct. + * @param {Aleph} a + * @param {null} b + */ + constructor(a, b) { + /** + * Field is always null + */ + this.field = b; + } + + /** + * Doesn't actually do anything + * @returns {void} + */ + doIt() {} +} + +/** + * Not the speed of light + */ +export const c = 12; + + +//// [source.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Foos a bar together using an `a` and a `b` + * @param {number} a + * @param {string} b + */ +function foo(a, b) { } +exports.foo = foo; +/** + * Legacy - DO NOT USE + */ +var Aleph = /** @class */ (function () { + /** + * Impossible to construct. + * @param {Aleph} a + * @param {null} b + */ + function Aleph(a, b) { + /** + * Field is always null + */ + this.field = b; + } + /** + * Doesn't actually do anything + * @returns {void} + */ + Aleph.prototype.doIt = function () { }; + return Aleph; +}()); +exports.Aleph = Aleph; +/** + * Not the speed of light + */ +exports.c = 12; + + +//// [source.d.ts] +/** + * Foos a bar together using an `a` and a `b` + * @param {number} a + * @param {string} b + */ +export function foo(a: number, b: string): void; +/** + * Legacy - DO NOT USE + */ +export class Aleph { + /** + * Impossible to construct. + * @param {Aleph} a + * @param {null} b + */ + constructor(a: Aleph, b: null); + /** + * Field is always null + */ + field: any; + /** + * Doesn't actually do anything + * @returns {void} + */ + doIt(): void; +} +/** + * Not the speed of light + */ +export const c: 12; diff --git a/tests/baselines/reference/jsDeclarationsFunctionJSDoc.symbols b/tests/baselines/reference/jsDeclarationsFunctionJSDoc.symbols new file mode 100644 index 0000000000000..27134d8058927 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionJSDoc.symbols @@ -0,0 +1,50 @@ +=== tests/cases/conformance/jsdoc/declarations/source.js === +/** + * Foos a bar together using an `a` and a `b` + * @param {number} a + * @param {string} b + */ +export function foo(a, b) {} +>foo : Symbol(foo, Decl(source.js, 0, 0)) +>a : Symbol(a, Decl(source.js, 5, 20)) +>b : Symbol(b, Decl(source.js, 5, 22)) + +/** + * Legacy - DO NOT USE + */ +export class Aleph { +>Aleph : Symbol(Aleph, Decl(source.js, 5, 28)) + + /** + * Impossible to construct. + * @param {Aleph} a + * @param {null} b + */ + constructor(a, b) { +>a : Symbol(a, Decl(source.js, 16, 16)) +>b : Symbol(b, Decl(source.js, 16, 18)) + + /** + * Field is always null + */ + this.field = b; +>this.field : Symbol(Aleph.field, Decl(source.js, 16, 23)) +>this : Symbol(Aleph, Decl(source.js, 5, 28)) +>field : Symbol(Aleph.field, Decl(source.js, 16, 23)) +>b : Symbol(b, Decl(source.js, 16, 18)) + } + + /** + * Doesn't actually do anything + * @returns {void} + */ + doIt() {} +>doIt : Symbol(Aleph.doIt, Decl(source.js, 21, 5)) +} + +/** + * Not the speed of light + */ +export const c = 12; +>c : Symbol(c, Decl(source.js, 33, 12)) + diff --git a/tests/baselines/reference/jsDeclarationsFunctionJSDoc.types b/tests/baselines/reference/jsDeclarationsFunctionJSDoc.types new file mode 100644 index 0000000000000..05dfcb0f492b8 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionJSDoc.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/jsdoc/declarations/source.js === +/** + * Foos a bar together using an `a` and a `b` + * @param {number} a + * @param {string} b + */ +export function foo(a, b) {} +>foo : (a: number, b: string) => void +>a : number +>b : string + +/** + * Legacy - DO NOT USE + */ +export class Aleph { +>Aleph : Aleph + + /** + * Impossible to construct. + * @param {Aleph} a + * @param {null} b + */ + constructor(a, b) { +>a : Aleph +>b : null + + /** + * Field is always null + */ + this.field = b; +>this.field = b : null +>this.field : any +>this : this +>field : any +>b : null + } + + /** + * Doesn't actually do anything + * @returns {void} + */ + doIt() {} +>doIt : () => void +} + +/** + * Not the speed of light + */ +export const c = 12; +>c : 12 +>12 : 12 + diff --git a/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.js b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.js new file mode 100644 index 0000000000000..96b9cfbd62b5a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.js @@ -0,0 +1,74 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses.ts] //// + +//// [source.js] +/** + * @param {number} x + * @param {number} y + */ +export function Point(x, y) { + if (!(this instanceof Point)) { + return new Point(x, y); + } + this.x = x; + this.y = y; +} + +//// [referencer.js] +import {Point} from "./source"; + +/** + * @param {Point} p + */ +export function magnitude(p) { + return Math.sqrt(p.x ** 2 + p.y ** 2); +} + + +//// [source.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * @param {number} x + * @param {number} y + */ +function Point(x, y) { + if (!(this instanceof Point)) { + return new Point(x, y); + } + this.x = x; + this.y = y; +} +exports.Point = Point; +//// [referencer.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * @param {Point} p + */ +function magnitude(p) { + return Math.sqrt(Math.pow(p.x, 2) + Math.pow(p.y, 2)); +} +exports.magnitude = magnitude; + + +//// [source.d.ts] +/** + * @param {number} x + * @param {number} y + */ +export function Point(x: number, y: number): Point; +export class Point { + /** + * @param {number} x + * @param {number} y + */ + constructor(x: number, y: number); + x: number; + y: number; +} +//// [referencer.d.ts] +/** + * @param {Point} p + */ +export function magnitude(p: Point): number; +import { Point } from "./source"; diff --git a/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.symbols b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.symbols new file mode 100644 index 0000000000000..61e0872f47979 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.symbols @@ -0,0 +1,50 @@ +=== tests/cases/conformance/jsdoc/declarations/source.js === +/** + * @param {number} x + * @param {number} y + */ +export function Point(x, y) { +>Point : Symbol(Point, Decl(source.js, 0, 0)) +>x : Symbol(x, Decl(source.js, 4, 22)) +>y : Symbol(y, Decl(source.js, 4, 24)) + + if (!(this instanceof Point)) { +>Point : Symbol(Point, Decl(source.js, 0, 0)) + + return new Point(x, y); +>Point : Symbol(Point, Decl(source.js, 0, 0)) +>x : Symbol(x, Decl(source.js, 4, 22)) +>y : Symbol(y, Decl(source.js, 4, 24)) + } + this.x = x; +>x : Symbol(Point.x, Decl(source.js, 7, 5)) +>x : Symbol(x, Decl(source.js, 4, 22)) + + this.y = y; +>y : Symbol(Point.y, Decl(source.js, 8, 15)) +>y : Symbol(y, Decl(source.js, 4, 24)) +} + +=== tests/cases/conformance/jsdoc/declarations/referencer.js === +import {Point} from "./source"; +>Point : Symbol(Point, Decl(referencer.js, 0, 8)) + +/** + * @param {Point} p + */ +export function magnitude(p) { +>magnitude : Symbol(magnitude, Decl(referencer.js, 0, 31)) +>p : Symbol(p, Decl(referencer.js, 5, 26)) + + return Math.sqrt(p.x ** 2 + p.y ** 2); +>Math.sqrt : Symbol(Math.sqrt, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>sqrt : Symbol(Math.sqrt, Decl(lib.es5.d.ts, --, --)) +>p.x : Symbol(Point.x, Decl(source.js, 7, 5)) +>p : Symbol(p, Decl(referencer.js, 5, 26)) +>x : Symbol(Point.x, Decl(source.js, 7, 5)) +>p.y : Symbol(Point.y, Decl(source.js, 8, 15)) +>p : Symbol(p, Decl(referencer.js, 5, 26)) +>y : Symbol(Point.y, Decl(source.js, 8, 15)) +} + diff --git a/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.types b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.types new file mode 100644 index 0000000000000..02ad20be62c8e --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses.types @@ -0,0 +1,67 @@ +=== tests/cases/conformance/jsdoc/declarations/source.js === +/** + * @param {number} x + * @param {number} y + */ +export function Point(x, y) { +>Point : typeof Point +>x : number +>y : number + + if (!(this instanceof Point)) { +>!(this instanceof Point) : boolean +>(this instanceof Point) : boolean +>this instanceof Point : boolean +>this : any +>Point : typeof Point + + return new Point(x, y); +>new Point(x, y) : Point +>Point : typeof Point +>x : number +>y : number + } + this.x = x; +>this.x = x : number +>this.x : any +>this : any +>x : any +>x : number + + this.y = y; +>this.y = y : number +>this.y : any +>this : any +>y : any +>y : number +} + +=== tests/cases/conformance/jsdoc/declarations/referencer.js === +import {Point} from "./source"; +>Point : typeof Point + +/** + * @param {Point} p + */ +export function magnitude(p) { +>magnitude : (p: Point) => number +>p : Point + + return Math.sqrt(p.x ** 2 + p.y ** 2); +>Math.sqrt(p.x ** 2 + p.y ** 2) : number +>Math.sqrt : (x: number) => number +>Math : Math +>sqrt : (x: number) => number +>p.x ** 2 + p.y ** 2 : number +>p.x ** 2 : number +>p.x : number +>p : Point +>x : number +>2 : 2 +>p.y ** 2 : number +>p.y : number +>p : Point +>y : number +>2 : 2 +} + diff --git a/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.js b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.js new file mode 100644 index 0000000000000..86aecfef4c961 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.js @@ -0,0 +1,193 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses2.ts] //// + +//// [source.js] +/** + * @param {number} len + */ +export function Vec(len) { + /** + * @type {number[]} + */ + this.storage = new Array(len); +} + +Vec.prototype = { + /** + * @param {Vec} other + */ + dot(other) { + if (other.storage.length !== this.storage.length) { + throw new Error(`Dot product only applicable for vectors of equal length`); + } + let sum = 0; + for (let i = 0; i < this.storage.length; i++) { + sum += (this.storage[i] * other.storage[i]); + } + return sum; + }, + magnitude() { + let sum = 0; + for (let i = 0; i < this.storage.length; i++) { + sum += (this.storage[i] ** 2); + } + return Math.sqrt(sum); + } +} + +/** + * @param {number} x + * @param {number} y + */ +export function Point2D(x, y) { + if (!(this instanceof Point2D)) { + return new Point2D(x, y); + } + Vec.call(this, 2); + this.x = x; + this.y = y; +} + +Point2D.prototype = { + __proto__: Vec, + get x() { + return this.storage[0]; + }, + /** + * @param {number} x + */ + set x(x) { + this.storage[0] = x; + }, + get y() { + return this.storage[1]; + }, + /** + * @param {number} y + */ + set y(y) { + this.storage[1] = y; + } +}; + +//// [referencer.js] +import {Point2D} from "./source"; + +export const origin = new Point2D(0, 0); +// export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this + + +//// [source.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * @param {number} len + */ +function Vec(len) { + /** + * @type {number[]} + */ + this.storage = new Array(len); +} +exports.Vec = Vec; +Vec.prototype = { + /** + * @param {Vec} other + */ + dot: function (other) { + if (other.storage.length !== this.storage.length) { + throw new Error("Dot product only applicable for vectors of equal length"); + } + var sum = 0; + for (var i = 0; i < this.storage.length; i++) { + sum += (this.storage[i] * other.storage[i]); + } + return sum; + }, + magnitude: function () { + var sum = 0; + for (var i = 0; i < this.storage.length; i++) { + sum += (Math.pow(this.storage[i], 2)); + } + return Math.sqrt(sum); + } +}; +/** + * @param {number} x + * @param {number} y + */ +function Point2D(x, y) { + if (!(this instanceof Point2D)) { + return new Point2D(x, y); + } + Vec.call(this, 2); + this.x = x; + this.y = y; +} +exports.Point2D = Point2D; +Point2D.prototype = { + __proto__: Vec, + get x() { + return this.storage[0]; + }, + /** + * @param {number} x + */ + set x(x) { + this.storage[0] = x; + }, + get y() { + return this.storage[1]; + }, + /** + * @param {number} y + */ + set y(y) { + this.storage[1] = y; + } +}; +//// [referencer.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var source_1 = require("./source"); +exports.origin = new source_1.Point2D(0, 0); +// export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this + + +//// [source.d.ts] +/** + * @param {number} len + */ +export function Vec(len: number): void; +export class Vec { + /** + * @param {number} len + */ + constructor(len: number); + /** + * @type {number[]} + */ + storage: number[]; + /** + * @param {Vec} other + */ + dot(other: Vec): number; + magnitude(): number; +} +/** + * @param {number} x + * @param {number} y + */ +export function Point2D(x: number, y: number): Point2D; +export class Point2D { + /** + * @param {number} x + * @param {number} y + */ + constructor(x: number, y: number); + x: number; + y: number; + __proto__: typeof Vec; +} +//// [referencer.d.ts] +export const origin: Point2D; +import { Point2D } from "./source"; diff --git a/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.symbols b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.symbols new file mode 100644 index 0000000000000..8e9894b37f96f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.symbols @@ -0,0 +1,192 @@ +=== tests/cases/conformance/jsdoc/declarations/source.js === +/** + * @param {number} len + */ +export function Vec(len) { +>Vec : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) +>len : Symbol(len, Decl(source.js, 3, 20)) + + /** + * @type {number[]} + */ + this.storage = new Array(len); +>storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>len : Symbol(len, Decl(source.js, 3, 20)) +} + +Vec.prototype = { +>Vec.prototype : Symbol(Vec.prototype, Decl(source.js, 8, 1)) +>Vec : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) +>prototype : Symbol(Vec.prototype, Decl(source.js, 8, 1)) + + /** + * @param {Vec} other + */ + dot(other) { +>dot : Symbol(dot, Decl(source.js, 10, 17)) +>other : Symbol(other, Decl(source.js, 14, 8)) + + if (other.storage.length !== this.storage.length) { +>other.storage.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>other.storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>other : Symbol(other, Decl(source.js, 14, 8)) +>storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>this.storage.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>this.storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>this : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) +>storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) + + throw new Error(`Dot product only applicable for vectors of equal length`); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } + let sum = 0; +>sum : Symbol(sum, Decl(source.js, 18, 11)) + + for (let i = 0; i < this.storage.length; i++) { +>i : Symbol(i, Decl(source.js, 19, 16)) +>i : Symbol(i, Decl(source.js, 19, 16)) +>this.storage.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>this.storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>this : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) +>storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(source.js, 19, 16)) + + sum += (this.storage[i] * other.storage[i]); +>sum : Symbol(sum, Decl(source.js, 18, 11)) +>this.storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>this : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) +>storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>i : Symbol(i, Decl(source.js, 19, 16)) +>other.storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>other : Symbol(other, Decl(source.js, 14, 8)) +>storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>i : Symbol(i, Decl(source.js, 19, 16)) + } + return sum; +>sum : Symbol(sum, Decl(source.js, 18, 11)) + + }, + magnitude() { +>magnitude : Symbol(magnitude, Decl(source.js, 23, 6)) + + let sum = 0; +>sum : Symbol(sum, Decl(source.js, 25, 11)) + + for (let i = 0; i < this.storage.length; i++) { +>i : Symbol(i, Decl(source.js, 26, 16)) +>i : Symbol(i, Decl(source.js, 26, 16)) +>this.storage.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>this.storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>this : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) +>storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(source.js, 26, 16)) + + sum += (this.storage[i] ** 2); +>sum : Symbol(sum, Decl(source.js, 25, 11)) +>this.storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>this : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) +>storage : Symbol(Vec.storage, Decl(source.js, 3, 26)) +>i : Symbol(i, Decl(source.js, 26, 16)) + } + return Math.sqrt(sum); +>Math.sqrt : Symbol(Math.sqrt, Decl(lib.es5.d.ts, --, --)) +>Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>sqrt : Symbol(Math.sqrt, Decl(lib.es5.d.ts, --, --)) +>sum : Symbol(sum, Decl(source.js, 25, 11)) + } +} + +/** + * @param {number} x + * @param {number} y + */ +export function Point2D(x, y) { +>Point2D : Symbol(Point2D, Decl(source.js, 31, 1), Decl(source.js, 44, 1)) +>x : Symbol(x, Decl(source.js, 37, 24)) +>y : Symbol(y, Decl(source.js, 37, 26)) + + if (!(this instanceof Point2D)) { +>Point2D : Symbol(Point2D, Decl(source.js, 31, 1), Decl(source.js, 44, 1)) + + return new Point2D(x, y); +>Point2D : Symbol(Point2D, Decl(source.js, 31, 1), Decl(source.js, 44, 1)) +>x : Symbol(x, Decl(source.js, 37, 24)) +>y : Symbol(y, Decl(source.js, 37, 26)) + } + Vec.call(this, 2); +>Vec.call : Symbol(Function.call, Decl(lib.es5.d.ts, --, --)) +>Vec : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) +>call : Symbol(Function.call, Decl(lib.es5.d.ts, --, --)) + + this.x = x; +>x : Symbol(Point2D.x, Decl(source.js, 41, 22), Decl(source.js, 47, 19), Decl(source.js, 50, 6)) +>x : Symbol(x, Decl(source.js, 37, 24)) + + this.y = y; +>y : Symbol(Point2D.y, Decl(source.js, 42, 15), Decl(source.js, 56, 6), Decl(source.js, 59, 6)) +>y : Symbol(y, Decl(source.js, 37, 26)) +} + +Point2D.prototype = { +>Point2D.prototype : Symbol(Point2D.prototype, Decl(source.js, 44, 1)) +>Point2D : Symbol(Point2D, Decl(source.js, 31, 1), Decl(source.js, 44, 1)) +>prototype : Symbol(Point2D.prototype, Decl(source.js, 44, 1)) + + __proto__: Vec, +>__proto__ : Symbol(__proto__, Decl(source.js, 46, 21)) +>Vec : Symbol(Vec, Decl(source.js, 0, 0), Decl(source.js, 8, 1)) + + get x() { +>x : Symbol(Point2D.x, Decl(source.js, 41, 22), Decl(source.js, 47, 19), Decl(source.js, 50, 6)) + + return this.storage[0]; +>this : Symbol(__object, Decl(source.js, 46, 19)) + + }, + /** + * @param {number} x + */ + set x(x) { +>x : Symbol(Point2D.x, Decl(source.js, 41, 22), Decl(source.js, 47, 19), Decl(source.js, 50, 6)) +>x : Symbol(x, Decl(source.js, 54, 10)) + + this.storage[0] = x; +>this : Symbol(__object, Decl(source.js, 46, 19)) +>x : Symbol(x, Decl(source.js, 54, 10)) + + }, + get y() { +>y : Symbol(Point2D.y, Decl(source.js, 42, 15), Decl(source.js, 56, 6), Decl(source.js, 59, 6)) + + return this.storage[1]; +>this : Symbol(__object, Decl(source.js, 46, 19)) + + }, + /** + * @param {number} y + */ + set y(y) { +>y : Symbol(Point2D.y, Decl(source.js, 42, 15), Decl(source.js, 56, 6), Decl(source.js, 59, 6)) +>y : Symbol(y, Decl(source.js, 63, 10)) + + this.storage[1] = y; +>this : Symbol(__object, Decl(source.js, 46, 19)) +>y : Symbol(y, Decl(source.js, 63, 10)) + } +}; + +=== tests/cases/conformance/jsdoc/declarations/referencer.js === +import {Point2D} from "./source"; +>Point2D : Symbol(Point2D, Decl(referencer.js, 0, 8)) + +export const origin = new Point2D(0, 0); +>origin : Symbol(origin, Decl(referencer.js, 2, 12)) +>Point2D : Symbol(Point2D, Decl(referencer.js, 0, 8)) + +// export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this + diff --git a/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.types b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.types new file mode 100644 index 0000000000000..3e94d055ee249 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionLikeClasses2.types @@ -0,0 +1,257 @@ +=== tests/cases/conformance/jsdoc/declarations/source.js === +/** + * @param {number} len + */ +export function Vec(len) { +>Vec : typeof Vec +>len : number + + /** + * @type {number[]} + */ + this.storage = new Array(len); +>this.storage = new Array(len) : any[] +>this.storage : any +>this : any +>storage : any +>new Array(len) : any[] +>Array : ArrayConstructor +>len : number +} + +Vec.prototype = { +>Vec.prototype = { /** * @param {Vec} other */ dot(other) { if (other.storage.length !== this.storage.length) { throw new Error(`Dot product only applicable for vectors of equal length`); } let sum = 0; for (let i = 0; i < this.storage.length; i++) { sum += (this.storage[i] * other.storage[i]); } return sum; }, magnitude() { let sum = 0; for (let i = 0; i < this.storage.length; i++) { sum += (this.storage[i] ** 2); } return Math.sqrt(sum); }} : { dot(other: Vec): number; magnitude(): number; } +>Vec.prototype : { dot(other: Vec): number; magnitude(): number; } +>Vec : typeof Vec +>prototype : { dot(other: Vec): number; magnitude(): number; } +>{ /** * @param {Vec} other */ dot(other) { if (other.storage.length !== this.storage.length) { throw new Error(`Dot product only applicable for vectors of equal length`); } let sum = 0; for (let i = 0; i < this.storage.length; i++) { sum += (this.storage[i] * other.storage[i]); } return sum; }, magnitude() { let sum = 0; for (let i = 0; i < this.storage.length; i++) { sum += (this.storage[i] ** 2); } return Math.sqrt(sum); }} : { dot(other: Vec): number; magnitude(): number; } + + /** + * @param {Vec} other + */ + dot(other) { +>dot : (other: Vec) => number +>other : Vec + + if (other.storage.length !== this.storage.length) { +>other.storage.length !== this.storage.length : boolean +>other.storage.length : number +>other.storage : number[] +>other : Vec +>storage : number[] +>length : number +>this.storage.length : number +>this.storage : number[] +>this : this +>storage : number[] +>length : number + + throw new Error(`Dot product only applicable for vectors of equal length`); +>new Error(`Dot product only applicable for vectors of equal length`) : Error +>Error : ErrorConstructor +>`Dot product only applicable for vectors of equal length` : "Dot product only applicable for vectors of equal length" + } + let sum = 0; +>sum : number +>0 : 0 + + for (let i = 0; i < this.storage.length; i++) { +>i : number +>0 : 0 +>i < this.storage.length : boolean +>i : number +>this.storage.length : number +>this.storage : number[] +>this : this +>storage : number[] +>length : number +>i++ : number +>i : number + + sum += (this.storage[i] * other.storage[i]); +>sum += (this.storage[i] * other.storage[i]) : number +>sum : number +>(this.storage[i] * other.storage[i]) : number +>this.storage[i] * other.storage[i] : number +>this.storage[i] : number +>this.storage : number[] +>this : this +>storage : number[] +>i : number +>other.storage[i] : number +>other.storage : number[] +>other : Vec +>storage : number[] +>i : number + } + return sum; +>sum : number + + }, + magnitude() { +>magnitude : () => number + + let sum = 0; +>sum : number +>0 : 0 + + for (let i = 0; i < this.storage.length; i++) { +>i : number +>0 : 0 +>i < this.storage.length : boolean +>i : number +>this.storage.length : number +>this.storage : number[] +>this : this +>storage : number[] +>length : number +>i++ : number +>i : number + + sum += (this.storage[i] ** 2); +>sum += (this.storage[i] ** 2) : number +>sum : number +>(this.storage[i] ** 2) : number +>this.storage[i] ** 2 : number +>this.storage[i] : number +>this.storage : number[] +>this : this +>storage : number[] +>i : number +>2 : 2 + } + return Math.sqrt(sum); +>Math.sqrt(sum) : number +>Math.sqrt : (x: number) => number +>Math : Math +>sqrt : (x: number) => number +>sum : number + } +} + +/** + * @param {number} x + * @param {number} y + */ +export function Point2D(x, y) { +>Point2D : typeof Point2D +>x : number +>y : number + + if (!(this instanceof Point2D)) { +>!(this instanceof Point2D) : boolean +>(this instanceof Point2D) : boolean +>this instanceof Point2D : boolean +>this : any +>Point2D : typeof Point2D + + return new Point2D(x, y); +>new Point2D(x, y) : Point2D +>Point2D : typeof Point2D +>x : number +>y : number + } + Vec.call(this, 2); +>Vec.call(this, 2) : any +>Vec.call : (this: Function, thisArg: any, ...argArray: any[]) => any +>Vec : typeof Vec +>call : (this: Function, thisArg: any, ...argArray: any[]) => any +>this : any +>2 : 2 + + this.x = x; +>this.x = x : number +>this.x : any +>this : any +>x : any +>x : number + + this.y = y; +>this.y = y : number +>this.y : any +>this : any +>y : any +>y : number +} + +Point2D.prototype = { +>Point2D.prototype = { __proto__: Vec, get x() { return this.storage[0]; }, /** * @param {number} x */ set x(x) { this.storage[0] = x; }, get y() { return this.storage[1]; }, /** * @param {number} y */ set y(y) { this.storage[1] = y; }} : { __proto__: typeof Vec; x: number; y: number; } +>Point2D.prototype : { __proto__: typeof Vec; x: number; y: number; } +>Point2D : typeof Point2D +>prototype : { __proto__: typeof Vec; x: number; y: number; } +>{ __proto__: Vec, get x() { return this.storage[0]; }, /** * @param {number} x */ set x(x) { this.storage[0] = x; }, get y() { return this.storage[1]; }, /** * @param {number} y */ set y(y) { this.storage[1] = y; }} : { __proto__: typeof Vec; x: number; y: number; } + + __proto__: Vec, +>__proto__ : typeof Vec +>Vec : typeof Vec + + get x() { +>x : number + + return this.storage[0]; +>this.storage[0] : any +>this.storage : any +>this : { __proto__: typeof Vec; x: number; y: number; } +>storage : any +>0 : 0 + + }, + /** + * @param {number} x + */ + set x(x) { +>x : number +>x : number + + this.storage[0] = x; +>this.storage[0] = x : number +>this.storage[0] : any +>this.storage : any +>this : { __proto__: typeof Vec; x: number; y: number; } +>storage : any +>0 : 0 +>x : number + + }, + get y() { +>y : number + + return this.storage[1]; +>this.storage[1] : any +>this.storage : any +>this : { __proto__: typeof Vec; x: number; y: number; } +>storage : any +>1 : 1 + + }, + /** + * @param {number} y + */ + set y(y) { +>y : number +>y : number + + this.storage[1] = y; +>this.storage[1] = y : number +>this.storage[1] : any +>this.storage : any +>this : { __proto__: typeof Vec; x: number; y: number; } +>storage : any +>1 : 1 +>y : number + } +}; + +=== tests/cases/conformance/jsdoc/declarations/referencer.js === +import {Point2D} from "./source"; +>Point2D : typeof Point2D + +export const origin = new Point2D(0, 0); +>origin : Point2D +>new Point2D(0, 0) : Point2D +>Point2D : typeof Point2D +>0 : 0 +>0 : 0 + +// export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this + diff --git a/tests/baselines/reference/jsDeclarationsFunctions.js b/tests/baselines/reference/jsDeclarationsFunctions.js new file mode 100644 index 0000000000000..c80fe43a1d2d4 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctions.js @@ -0,0 +1,177 @@ +//// [index.js] +export function a() {} + +export function b() {} +b.cat = "cat"; + +export function c() {} +c.Cls = class {} + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +export function d(a, b) { return /** @type {*} */(null); } + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +export function e(a, b) { return /** @type {*} */(null); } + +/** + * @template T + * @param {T} a + */ +export function f(a) { + return a; +} +f.self = f; + +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function g(a, b) { + return a.x && b.y(); +} + +export { g }; + +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} + +export { hh as h }; + +export function i() {} +export { i as ii }; + +export { j as jj }; +export function j() {} + + +//// [index.js] +"use strict"; +exports.__esModule = true; +function a() { } +exports.a = a; +function b() { } +exports.b = b; +b.cat = "cat"; +function c() { } +exports.c = c; +c.Cls = /** @class */ (function () { + function Cls() { + } + return Cls; +}()); +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +function d(a, b) { return /** @type {*} */ (null); } +exports.d = d; +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +function e(a, b) { return /** @type {*} */ (null); } +exports.e = e; +/** + * @template T + * @param {T} a + */ +function f(a) { + return a; +} +exports.f = f; +f.self = f; +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function g(a, b) { + return a.x && b.y(); +} +exports.g = g; +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} +exports.h = hh; +function i() { } +exports.i = i; +exports.ii = i; +function j() { } +exports.j = j; +exports.jj = j; + + +//// [index.d.ts] +export function a(): void; +export function b(): void; +export namespace b { + export const cat: string; +} +export function c(): void; +export namespace c { + export { Cls }; + class Cls { + } +} +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +export function d(a: number, b: number): string; +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +export function e(a: T, b: U): T & U; +/** + * @template T + * @param {T} a + */ +export function f(a: T): T; +export namespace f { + export { f as self }; +} +export function i(): void; +export function j(): void; +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +export function g(a: { + x: string; +}, b: { + y: typeof b; +}): void; +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +declare function hh(a: { + x: string; +}, b: { + y: typeof b; +}): void; +export { hh as h, i as ii, j as jj }; diff --git a/tests/baselines/reference/jsDeclarationsFunctions.symbols b/tests/baselines/reference/jsDeclarationsFunctions.symbols new file mode 100644 index 0000000000000..0f2a41a6222d8 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctions.symbols @@ -0,0 +1,115 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +export function a() {} +>a : Symbol(a, Decl(index.js, 0, 0)) + +export function b() {} +>b : Symbol(b, Decl(index.js, 0, 22), Decl(index.js, 2, 22)) + +b.cat = "cat"; +>b.cat : Symbol(b.cat, Decl(index.js, 2, 22)) +>b : Symbol(b, Decl(index.js, 0, 22), Decl(index.js, 2, 22)) +>cat : Symbol(b.cat, Decl(index.js, 2, 22)) + +export function c() {} +>c : Symbol(c, Decl(index.js, 3, 14), Decl(index.js, 5, 22)) + +c.Cls = class {} +>c.Cls : Symbol(c.Cls, Decl(index.js, 5, 22)) +>c : Symbol(c, Decl(index.js, 3, 14), Decl(index.js, 5, 22)) +>Cls : Symbol(c.Cls, Decl(index.js, 5, 22)) + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +export function d(a, b) { return /** @type {*} */(null); } +>d : Symbol(d, Decl(index.js, 6, 16)) +>a : Symbol(a, Decl(index.js, 13, 18)) +>b : Symbol(b, Decl(index.js, 13, 20)) + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +export function e(a, b) { return /** @type {*} */(null); } +>e : Symbol(e, Decl(index.js, 13, 58)) +>a : Symbol(a, Decl(index.js, 21, 18)) +>b : Symbol(b, Decl(index.js, 21, 20)) + +/** + * @template T + * @param {T} a + */ +export function f(a) { +>f : Symbol(f, Decl(index.js, 21, 58), Decl(index.js, 29, 1)) +>a : Symbol(a, Decl(index.js, 27, 18)) + + return a; +>a : Symbol(a, Decl(index.js, 27, 18)) +} +f.self = f; +>f.self : Symbol(f.self, Decl(index.js, 29, 1)) +>f : Symbol(f, Decl(index.js, 21, 58), Decl(index.js, 29, 1)) +>self : Symbol(f.self, Decl(index.js, 29, 1)) +>f : Symbol(f, Decl(index.js, 21, 58), Decl(index.js, 29, 1)) + +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function g(a, b) { +>g : Symbol(g, Decl(index.js, 30, 11)) +>a : Symbol(a, Decl(index.js, 36, 11)) +>b : Symbol(b, Decl(index.js, 36, 13)) + + return a.x && b.y(); +>a.x : Symbol(x, Decl(index.js, 33, 12)) +>a : Symbol(a, Decl(index.js, 36, 11)) +>x : Symbol(x, Decl(index.js, 33, 12)) +>b.y : Symbol(y, Decl(index.js, 34, 12)) +>b : Symbol(b, Decl(index.js, 36, 13)) +>y : Symbol(y, Decl(index.js, 34, 12)) +} + +export { g }; +>g : Symbol(g, Decl(index.js, 40, 8)) + +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function hh(a, b) { +>hh : Symbol(hh, Decl(index.js, 40, 13)) +>a : Symbol(a, Decl(index.js, 46, 12)) +>b : Symbol(b, Decl(index.js, 46, 14)) + + return a.x && b.y(); +>a.x : Symbol(x, Decl(index.js, 43, 12)) +>a : Symbol(a, Decl(index.js, 46, 12)) +>x : Symbol(x, Decl(index.js, 43, 12)) +>b.y : Symbol(y, Decl(index.js, 44, 12)) +>b : Symbol(b, Decl(index.js, 46, 14)) +>y : Symbol(y, Decl(index.js, 44, 12)) +} + +export { hh as h }; +>hh : Symbol(hh, Decl(index.js, 40, 13)) +>h : Symbol(h, Decl(index.js, 50, 8)) + +export function i() {} +>i : Symbol(i, Decl(index.js, 50, 19)) + +export { i as ii }; +>i : Symbol(i, Decl(index.js, 50, 19)) +>ii : Symbol(ii, Decl(index.js, 53, 8)) + +export { j as jj }; +>j : Symbol(j, Decl(index.js, 55, 19)) +>jj : Symbol(jj, Decl(index.js, 55, 8)) + +export function j() {} +>j : Symbol(j, Decl(index.js, 55, 19)) + diff --git a/tests/baselines/reference/jsDeclarationsFunctions.types b/tests/baselines/reference/jsDeclarationsFunctions.types new file mode 100644 index 0000000000000..72d67885c2d61 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctions.types @@ -0,0 +1,128 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +export function a() {} +>a : () => void + +export function b() {} +>b : typeof b + +b.cat = "cat"; +>b.cat = "cat" : "cat" +>b.cat : string +>b : typeof b +>cat : string +>"cat" : "cat" + +export function c() {} +>c : typeof c + +c.Cls = class {} +>c.Cls = class {} : typeof Cls +>c.Cls : typeof Cls +>c : typeof c +>Cls : typeof Cls +>class {} : typeof Cls + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +export function d(a, b) { return /** @type {*} */(null); } +>d : (a: number, b: number) => string +>a : number +>b : number +>(null) : any +>null : null + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +export function e(a, b) { return /** @type {*} */(null); } +>e : (a: T, b: U) => T & U +>a : T +>b : U +>(null) : any +>null : null + +/** + * @template T + * @param {T} a + */ +export function f(a) { +>f : typeof f +>a : T + + return a; +>a : T +} +f.self = f; +>f.self = f : typeof f +>f.self : typeof f +>f : typeof f +>self : typeof f +>f : typeof f + +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function g(a, b) { +>g : (a: { x: string; }, b: { y: typeof import("tests/cases/conformance/jsdoc/declarations/index").b; }) => void +>a : { x: string; } +>b : { y: typeof import("tests/cases/conformance/jsdoc/declarations/index").b; } + + return a.x && b.y(); +>a.x && b.y() : void +>a.x : string +>a : { x: string; } +>x : string +>b.y() : void +>b.y : typeof import("tests/cases/conformance/jsdoc/declarations/index").b +>b : { y: typeof import("tests/cases/conformance/jsdoc/declarations/index").b; } +>y : typeof import("tests/cases/conformance/jsdoc/declarations/index").b +} + +export { g }; +>g : (a: { x: string; }, b: { y: typeof b; }) => void + +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function hh(a, b) { +>hh : (a: { x: string; }, b: { y: typeof import("tests/cases/conformance/jsdoc/declarations/index").b; }) => void +>a : { x: string; } +>b : { y: typeof import("tests/cases/conformance/jsdoc/declarations/index").b; } + + return a.x && b.y(); +>a.x && b.y() : void +>a.x : string +>a : { x: string; } +>x : string +>b.y() : void +>b.y : typeof import("tests/cases/conformance/jsdoc/declarations/index").b +>b : { y: typeof import("tests/cases/conformance/jsdoc/declarations/index").b; } +>y : typeof import("tests/cases/conformance/jsdoc/declarations/index").b +} + +export { hh as h }; +>hh : (a: { x: string; }, b: { y: typeof b; }) => void +>h : (a: { x: string; }, b: { y: typeof b; }) => void + +export function i() {} +>i : () => void + +export { i as ii }; +>i : () => void +>ii : () => void + +export { j as jj }; +>j : () => void +>jj : () => void + +export function j() {} +>j : () => void + diff --git a/tests/baselines/reference/jsDeclarationsFunctionsCjs.js b/tests/baselines/reference/jsDeclarationsFunctionsCjs.js new file mode 100644 index 0000000000000..6e80a0b4b17c6 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionsCjs.js @@ -0,0 +1,161 @@ +//// [index.js] +module.exports.a = function a() {} + +module.exports.b = function b() {} +module.exports.b.cat = "cat"; + +module.exports.c = function c() {} +module.exports.c.Cls = class {} + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +module.exports.d = function d(a, b) { return /** @type {*} */(null); } + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +module.exports.e = function e(a, b) { return /** @type {*} */(null); } + +/** + * @template T + * @param {T} a + */ +module.exports.f = function f(a) { + return a; +} +module.exports.f.self = module.exports.f; + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { + return a.x && b.y(); +} + +module.exports.g = g; + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} + +module.exports.h = hh; + +module.exports.i = function i() {} +module.exports.ii = module.exports.i; + +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +module.exports.jj = module.exports.j; +module.exports.j = function j() {} + + +//// [index.js] +module.exports.a = function a() { }; +module.exports.b = function b() { }; +module.exports.b.cat = "cat"; +module.exports.c = function c() { }; +module.exports.c.Cls = /** @class */ (function () { + function Cls() { + } + return Cls; +}()); +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +module.exports.d = function d(a, b) { return /** @type {*} */ (null); }; +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +module.exports.e = function e(a, b) { return /** @type {*} */ (null); }; +/** + * @template T + * @param {T} a + */ +module.exports.f = function f(a) { + return a; +}; +module.exports.f.self = module.exports.f; +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { + return a.x && b.y(); +} +module.exports.g = g; +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} +module.exports.h = hh; +module.exports.i = function i() { }; +module.exports.ii = module.exports.i; +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +module.exports.jj = module.exports.j; +module.exports.j = function j() { }; + + +//// [index.d.ts] +export function a(): void; +export function b(): void; +export namespace b { + export const cat: string; +} +export function c(): void; +export namespace c { + class Cls { + } +} +export function d(a: number, b: number): string; +export function e(a: T, b: U): T & U; +export function f(a: T): T; +export namespace f { + import self = f; + export { self }; +} +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +export function g(a: { + x: string; +}, b: { + y: { + (): void; + cat: string; + }; +}): void; +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +export function h(a: { + x: string; +}, b: { + y: { + (): void; + cat: string; + }; +}): void; +export function i(): void; +export function ii(): void; +export function jj(): void; +export function j(): void; diff --git a/tests/baselines/reference/jsDeclarationsFunctionsCjs.symbols b/tests/baselines/reference/jsDeclarationsFunctionsCjs.symbols new file mode 100644 index 0000000000000..b900de3c1f076 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionsCjs.symbols @@ -0,0 +1,197 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +module.exports.a = function a() {} +>module.exports.a : Symbol(a, Decl(index.js, 0, 0)) +>module.exports : Symbol(a, Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>a : Symbol(a, Decl(index.js, 0, 0)) +>a : Symbol(a, Decl(index.js, 0, 18)) + +module.exports.b = function b() {} +>module.exports.b : Symbol(b, Decl(index.js, 0, 34), Decl(index.js, 3, 15)) +>module.exports : Symbol(b, Decl(index.js, 0, 34), Decl(index.js, 3, 15)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>b : Symbol(b, Decl(index.js, 0, 34), Decl(index.js, 3, 15)) +>b : Symbol(b, Decl(index.js, 2, 18)) + +module.exports.b.cat = "cat"; +>module.exports.b.cat : Symbol(b.cat, Decl(index.js, 2, 34)) +>module.exports.b : Symbol(b.cat, Decl(index.js, 2, 34)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>b : Symbol(b, Decl(index.js, 0, 34), Decl(index.js, 3, 15)) +>cat : Symbol(b.cat, Decl(index.js, 2, 34)) + +module.exports.c = function c() {} +>module.exports.c : Symbol(c, Decl(index.js, 3, 29), Decl(index.js, 6, 15)) +>module.exports : Symbol(c, Decl(index.js, 3, 29), Decl(index.js, 6, 15)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>c : Symbol(c, Decl(index.js, 3, 29), Decl(index.js, 6, 15)) +>c : Symbol(c, Decl(index.js, 5, 18)) + +module.exports.c.Cls = class {} +>module.exports.c.Cls : Symbol(c.Cls, Decl(index.js, 5, 34)) +>module.exports.c : Symbol(c.Cls, Decl(index.js, 5, 34)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>c : Symbol(c, Decl(index.js, 3, 29), Decl(index.js, 6, 15)) +>Cls : Symbol(c.Cls, Decl(index.js, 5, 34)) + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +module.exports.d = function d(a, b) { return /** @type {*} */(null); } +>module.exports.d : Symbol(d, Decl(index.js, 6, 31)) +>module.exports : Symbol(d, Decl(index.js, 6, 31)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>d : Symbol(d, Decl(index.js, 6, 31)) +>d : Symbol(d, Decl(index.js, 13, 18)) +>a : Symbol(a, Decl(index.js, 13, 30)) +>b : Symbol(b, Decl(index.js, 13, 32)) + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +module.exports.e = function e(a, b) { return /** @type {*} */(null); } +>module.exports.e : Symbol(e, Decl(index.js, 13, 70)) +>module.exports : Symbol(e, Decl(index.js, 13, 70)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>e : Symbol(e, Decl(index.js, 13, 70)) +>e : Symbol(e, Decl(index.js, 21, 18)) +>a : Symbol(a, Decl(index.js, 21, 30)) +>b : Symbol(b, Decl(index.js, 21, 32)) + +/** + * @template T + * @param {T} a + */ +module.exports.f = function f(a) { +>module.exports.f : Symbol(f, Decl(index.js, 21, 70), Decl(index.js, 30, 15)) +>module.exports : Symbol(f, Decl(index.js, 21, 70), Decl(index.js, 30, 15)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>f : Symbol(f, Decl(index.js, 21, 70), Decl(index.js, 30, 15)) +>f : Symbol(f, Decl(index.js, 27, 18)) +>a : Symbol(a, Decl(index.js, 27, 30)) + + return a; +>a : Symbol(a, Decl(index.js, 27, 30)) +} +module.exports.f.self = module.exports.f; +>module.exports.f.self : Symbol(f.self, Decl(index.js, 29, 1)) +>module.exports.f : Symbol(f.self, Decl(index.js, 29, 1)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>f : Symbol(f, Decl(index.js, 21, 70), Decl(index.js, 30, 15)) +>self : Symbol(f.self, Decl(index.js, 29, 1)) +>module.exports.f : Symbol(f, Decl(index.js, 21, 70), Decl(index.js, 30, 15)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>f : Symbol(f, Decl(index.js, 21, 70), Decl(index.js, 30, 15)) + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { +>g : Symbol(g, Decl(index.js, 30, 41)) +>a : Symbol(a, Decl(index.js, 36, 11)) +>b : Symbol(b, Decl(index.js, 36, 13)) + + return a.x && b.y(); +>a.x : Symbol(x, Decl(index.js, 33, 12)) +>a : Symbol(a, Decl(index.js, 36, 11)) +>x : Symbol(x, Decl(index.js, 33, 12)) +>b.y : Symbol(y, Decl(index.js, 34, 12)) +>b : Symbol(b, Decl(index.js, 36, 13)) +>y : Symbol(y, Decl(index.js, 34, 12)) +} + +module.exports.g = g; +>module.exports.g : Symbol(g, Decl(index.js, 38, 1)) +>module.exports : Symbol(g, Decl(index.js, 38, 1)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>g : Symbol(g, Decl(index.js, 38, 1)) +>g : Symbol(g, Decl(index.js, 30, 41)) + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { +>hh : Symbol(hh, Decl(index.js, 40, 21)) +>a : Symbol(a, Decl(index.js, 46, 12)) +>b : Symbol(b, Decl(index.js, 46, 14)) + + return a.x && b.y(); +>a.x : Symbol(x, Decl(index.js, 43, 12)) +>a : Symbol(a, Decl(index.js, 46, 12)) +>x : Symbol(x, Decl(index.js, 43, 12)) +>b.y : Symbol(y, Decl(index.js, 44, 12)) +>b : Symbol(b, Decl(index.js, 46, 14)) +>y : Symbol(y, Decl(index.js, 44, 12)) +} + +module.exports.h = hh; +>module.exports.h : Symbol(h, Decl(index.js, 48, 1)) +>module.exports : Symbol(h, Decl(index.js, 48, 1)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>h : Symbol(h, Decl(index.js, 48, 1)) +>hh : Symbol(hh, Decl(index.js, 40, 21)) + +module.exports.i = function i() {} +>module.exports.i : Symbol(i, Decl(index.js, 50, 22)) +>module.exports : Symbol(i, Decl(index.js, 50, 22)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>i : Symbol(i, Decl(index.js, 50, 22)) +>i : Symbol(i, Decl(index.js, 52, 18)) + +module.exports.ii = module.exports.i; +>module.exports.ii : Symbol(ii, Decl(index.js, 52, 34)) +>module.exports : Symbol(ii, Decl(index.js, 52, 34)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>ii : Symbol(ii, Decl(index.js, 52, 34)) +>module.exports.i : Symbol(i, Decl(index.js, 50, 22)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>i : Symbol(i, Decl(index.js, 50, 22)) + +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +module.exports.jj = module.exports.j; +>module.exports.jj : Symbol(jj, Decl(index.js, 53, 37)) +>module.exports : Symbol(jj, Decl(index.js, 53, 37)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>jj : Symbol(jj, Decl(index.js, 53, 37)) +>module.exports.j : Symbol(j, Decl(index.js, 56, 37)) +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>j : Symbol(j, Decl(index.js, 56, 37)) + +module.exports.j = function j() {} +>module.exports.j : Symbol(j, Decl(index.js, 56, 37)) +>module.exports : Symbol(j, Decl(index.js, 56, 37)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>j : Symbol(j, Decl(index.js, 56, 37)) +>j : Symbol(j, Decl(index.js, 57, 18)) + diff --git a/tests/baselines/reference/jsDeclarationsFunctionsCjs.types b/tests/baselines/reference/jsDeclarationsFunctionsCjs.types new file mode 100644 index 0000000000000..ec6843764ff39 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsFunctionsCjs.types @@ -0,0 +1,230 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +module.exports.a = function a() {} +>module.exports.a = function a() {} : () => void +>module.exports.a : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>a : () => void +>function a() {} : () => void +>a : () => void + +module.exports.b = function b() {} +>module.exports.b = function b() {} : { (): void; cat: string; } +>module.exports.b : { (): void; cat: string; } +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>b : { (): void; cat: string; } +>function b() {} : { (): void; cat: string; } +>b : { (): void; cat: string; } + +module.exports.b.cat = "cat"; +>module.exports.b.cat = "cat" : "cat" +>module.exports.b.cat : string +>module.exports.b : { (): void; cat: string; } +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>b : { (): void; cat: string; } +>cat : string +>"cat" : "cat" + +module.exports.c = function c() {} +>module.exports.c = function c() {} : { (): void; Cls: typeof Cls; } +>module.exports.c : { (): void; Cls: typeof Cls; } +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>c : { (): void; Cls: typeof Cls; } +>function c() {} : { (): void; Cls: typeof Cls; } +>c : { (): void; Cls: typeof Cls; } + +module.exports.c.Cls = class {} +>module.exports.c.Cls = class {} : typeof Cls +>module.exports.c.Cls : typeof Cls +>module.exports.c : { (): void; Cls: typeof Cls; } +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>c : { (): void; Cls: typeof Cls; } +>Cls : typeof Cls +>class {} : typeof Cls + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +module.exports.d = function d(a, b) { return /** @type {*} */(null); } +>module.exports.d = function d(a, b) { return /** @type {*} */(null); } : (a: number, b: number) => string +>module.exports.d : (a: number, b: number) => string +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>d : (a: number, b: number) => string +>function d(a, b) { return /** @type {*} */(null); } : (a: number, b: number) => string +>d : (a: number, b: number) => string +>a : number +>b : number +>(null) : any +>null : null + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +module.exports.e = function e(a, b) { return /** @type {*} */(null); } +>module.exports.e = function e(a, b) { return /** @type {*} */(null); } : (a: T, b: U) => T & U +>module.exports.e : (a: T, b: U) => T & U +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>e : (a: T, b: U) => T & U +>function e(a, b) { return /** @type {*} */(null); } : (a: T, b: U) => T & U +>e : (a: T, b: U) => T & U +>a : T +>b : U +>(null) : any +>null : null + +/** + * @template T + * @param {T} a + */ +module.exports.f = function f(a) { +>module.exports.f = function f(a) { return a;} : { (a: T): T; self: any; } +>module.exports.f : { (a: T): T; self: any; } +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>f : { (a: T): T; self: any; } +>function f(a) { return a;} : { (a: T): T; self: any; } +>f : { (a: T): T; self: any; } +>a : T + + return a; +>a : T +} +module.exports.f.self = module.exports.f; +>module.exports.f.self = module.exports.f : { (a: T): T; self: any; } +>module.exports.f.self : { (a: T): T; self: any; } +>module.exports.f : { (a: T): T; self: any; } +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>f : { (a: T): T; self: any; } +>self : { (a: T): T; self: any; } +>module.exports.f : { (a: T): T; self: any; } +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>f : { (a: T): T; self: any; } + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { +>g : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void +>a : { x: string; } +>b : { y: { (): void; cat: string; }; } + + return a.x && b.y(); +>a.x && b.y() : void +>a.x : string +>a : { x: string; } +>x : string +>b.y() : void +>b.y : { (): void; cat: string; } +>b : { y: { (): void; cat: string; }; } +>y : { (): void; cat: string; } +} + +module.exports.g = g; +>module.exports.g = g : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void +>module.exports.g : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>g : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void +>g : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { +>hh : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void +>a : { x: string; } +>b : { y: { (): void; cat: string; }; } + + return a.x && b.y(); +>a.x && b.y() : void +>a.x : string +>a : { x: string; } +>x : string +>b.y() : void +>b.y : { (): void; cat: string; } +>b : { y: { (): void; cat: string; }; } +>y : { (): void; cat: string; } +} + +module.exports.h = hh; +>module.exports.h = hh : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void +>module.exports.h : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>h : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void +>hh : (a: { x: string; }, b: { y: { (): void; cat: string; }; }) => void + +module.exports.i = function i() {} +>module.exports.i = function i() {} : () => void +>module.exports.i : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>i : () => void +>function i() {} : () => void +>i : () => void + +module.exports.ii = module.exports.i; +>module.exports.ii = module.exports.i : () => void +>module.exports.ii : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>ii : () => void +>module.exports.i : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>i : () => void + +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +module.exports.jj = module.exports.j; +>module.exports.jj = module.exports.j : () => void +>module.exports.jj : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>jj : () => void +>module.exports.j : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>j : () => void + +module.exports.j = function j() {} +>module.exports.j = function j() {} : () => void +>module.exports.j : () => void +>module.exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof import("tests/cases/conformance/jsdoc/declarations/index"); } +>exports : typeof import("tests/cases/conformance/jsdoc/declarations/index") +>j : () => void +>function j() {} : () => void +>j : () => void + diff --git a/tests/baselines/reference/jsDeclarationsImportTypeBundled.js b/tests/baselines/reference/jsDeclarationsImportTypeBundled.js new file mode 100644 index 0000000000000..13d62d4e18337 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsImportTypeBundled.js @@ -0,0 +1,52 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsImportTypeBundled.ts] //// + +//// [mod1.js] +/** + * @typedef {{x: number}} Item + */ +/** + * @type {Item}; + */ +const x = {x: 12}; +module.exports = x; +//// [index.js] +/** @type {(typeof import("./folder/mod1"))[]} */ +const items = [{x: 12}]; +module.exports = items; + +//// [out.js] +/** + * @typedef {{x: number}} Item + */ +/** + * @type {Item}; + */ +var x = { x: 12 }; +module.exports = x; +/** @type {(typeof import("./folder/mod1"))[]} */ +var items = [{ x: 12 }]; +module.exports = items; + + +//// [out.d.ts] +declare module "folder/mod1" { + export = x; + /** + * @typedef {{x: number}} Item + */ + /** + * @type {Item}; + */ + const x: Item; + namespace x { + export { Item }; + } + type Item = { + x: number; + }; +} +declare module "index" { + export = items; + /** @type {(typeof import("./folder/mod1"))[]} */ + const items: (typeof import("folder/mod1"))[]; +} diff --git a/tests/baselines/reference/jsDeclarationsImportTypeBundled.symbols b/tests/baselines/reference/jsDeclarationsImportTypeBundled.symbols new file mode 100644 index 0000000000000..7cf1f7a1b236c --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsImportTypeBundled.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/jsdoc/declarations/folder/mod1.js === +/** + * @typedef {{x: number}} Item + */ +/** + * @type {Item}; + */ +const x = {x: 12}; +>x : Symbol(x, Decl(mod1.js, 6, 5)) +>x : Symbol(x, Decl(mod1.js, 6, 11)) + +module.exports = x; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/folder/mod1", Decl(mod1.js, 0, 0)) +>module : Symbol(export=, Decl(mod1.js, 6, 18)) +>exports : Symbol(export=, Decl(mod1.js, 6, 18)) +>x : Symbol(x, Decl(mod1.js, 6, 5)) + +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** @type {(typeof import("./folder/mod1"))[]} */ +const items = [{x: 12}]; +>items : Symbol(items, Decl(index.js, 1, 5)) +>x : Symbol(x, Decl(index.js, 1, 16)) + +module.exports = items; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 1, 24)) +>exports : Symbol(export=, Decl(index.js, 1, 24)) +>items : Symbol(items, Decl(index.js, 1, 5)) + diff --git a/tests/baselines/reference/jsDeclarationsImportTypeBundled.types b/tests/baselines/reference/jsDeclarationsImportTypeBundled.types new file mode 100644 index 0000000000000..8236fa5d9184d --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsImportTypeBundled.types @@ -0,0 +1,36 @@ +=== tests/cases/conformance/jsdoc/declarations/folder/mod1.js === +/** + * @typedef {{x: number}} Item + */ +/** + * @type {Item}; + */ +const x = {x: 12}; +>x : { x: number; } +>{x: 12} : { x: number; } +>x : number +>12 : 12 + +module.exports = x; +>module.exports = x : { x: number; } +>module.exports : { x: number; } +>module : { "tests/cases/conformance/jsdoc/declarations/folder/mod1": { x: number; }; } +>exports : { x: number; } +>x : { x: number; } + +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** @type {(typeof import("./folder/mod1"))[]} */ +const items = [{x: 12}]; +>items : { x: number; }[] +>[{x: 12}] : { x: number; }[] +>{x: 12} : { x: number; } +>x : number +>12 : 12 + +module.exports = items; +>module.exports = items : { [n: number]: { x: number; }; length: number; toString(): string; toLocaleString(): string; pop(): { x: number; }; push(...items: { x: number; }[]): number; concat(...items: ConcatArray<{ x: number; }>[]): { x: number; }[]; concat(...items: ({ x: number; } | ConcatArray<{ x: number; }>)[]): { x: number; }[]; join(separator?: string): string; reverse(): { x: number; }[]; shift(): { x: number; }; slice(start?: number, end?: number): { x: number; }[]; sort(compareFn?: (a: { x: number; }, b: { x: number; }) => number): { x: number; }[]; splice(start: number, deleteCount?: number): { x: number; }[]; splice(start: number, deleteCount: number, ...items: { x: number; }[]): { x: number; }[]; unshift(...items: { x: number; }[]): number; indexOf(searchElement: { x: number; }, fromIndex?: number): number; lastIndexOf(searchElement: { x: number; }, fromIndex?: number): number; every(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => void, thisArg?: any): void; map(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): { x: number; }[]; reduce(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }): { x: number; }; reduce(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }, initialValue: { x: number; }): { x: number; }; reduce(callbackfn: (previousValue: U, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }): { x: number; }; reduceRight(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }, initialValue: { x: number; }): { x: number; }; reduceRight(callbackfn: (previousValue: U, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => U, initialValue: U): U; } +>module.exports : { [n: number]: { x: number; }; length: number; toString(): string; toLocaleString(): string; pop(): { x: number; }; push(...items: { x: number; }[]): number; concat(...items: ConcatArray<{ x: number; }>[]): { x: number; }[]; concat(...items: ({ x: number; } | ConcatArray<{ x: number; }>)[]): { x: number; }[]; join(separator?: string): string; reverse(): { x: number; }[]; shift(): { x: number; }; slice(start?: number, end?: number): { x: number; }[]; sort(compareFn?: (a: { x: number; }, b: { x: number; }) => number): { x: number; }[]; splice(start: number, deleteCount?: number): { x: number; }[]; splice(start: number, deleteCount: number, ...items: { x: number; }[]): { x: number; }[]; unshift(...items: { x: number; }[]): number; indexOf(searchElement: { x: number; }, fromIndex?: number): number; lastIndexOf(searchElement: { x: number; }, fromIndex?: number): number; every(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => void, thisArg?: any): void; map(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): { x: number; }[]; reduce(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }): { x: number; }; reduce(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }, initialValue: { x: number; }): { x: number; }; reduce(callbackfn: (previousValue: U, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }): { x: number; }; reduceRight(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }, initialValue: { x: number; }): { x: number; }; reduceRight(callbackfn: (previousValue: U, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => U, initialValue: U): U; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { [n: number]: { x: number; }; length: number; toString(): string; toLocaleString(): string; pop(): { x: number; }; push(...items: { x: number; }[]): number; concat(...items: ConcatArray<{ x: number; }>[]): { x: number; }[]; concat(...items: ({ x: number; } | ConcatArray<{ x: number; }>)[]): { x: number; }[]; join(separator?: string): string; reverse(): { x: number; }[]; shift(): { x: number; }; slice(start?: number, end?: number): { x: number; }[]; sort(compareFn?: (a: { x: number; }, b: { x: number; }) => number): { x: number; }[]; splice(start: number, deleteCount?: number): { x: number; }[]; splice(start: number, deleteCount: number, ...items: { x: number; }[]): { x: number; }[]; unshift(...items: { x: number; }[]): number; indexOf(searchElement: { x: number; }, fromIndex?: number): number; lastIndexOf(searchElement: { x: number; }, fromIndex?: number): number; every(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => void, thisArg?: any): void; map(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): { x: number; }[]; reduce(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }): { x: number; }; reduce(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }, initialValue: { x: number; }): { x: number; }; reduce(callbackfn: (previousValue: U, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }): { x: number; }; reduceRight(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }, initialValue: { x: number; }): { x: number; }; reduceRight(callbackfn: (previousValue: U, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => U, initialValue: U): U; }; } +>exports : { [n: number]: { x: number; }; length: number; toString(): string; toLocaleString(): string; pop(): { x: number; }; push(...items: { x: number; }[]): number; concat(...items: ConcatArray<{ x: number; }>[]): { x: number; }[]; concat(...items: ({ x: number; } | ConcatArray<{ x: number; }>)[]): { x: number; }[]; join(separator?: string): string; reverse(): { x: number; }[]; shift(): { x: number; }; slice(start?: number, end?: number): { x: number; }[]; sort(compareFn?: (a: { x: number; }, b: { x: number; }) => number): { x: number; }[]; splice(start: number, deleteCount?: number): { x: number; }[]; splice(start: number, deleteCount: number, ...items: { x: number; }[]): { x: number; }[]; unshift(...items: { x: number; }[]): number; indexOf(searchElement: { x: number; }, fromIndex?: number): number; lastIndexOf(searchElement: { x: number; }, fromIndex?: number): number; every(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => void, thisArg?: any): void; map(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => unknown, thisArg?: any): { x: number; }[]; reduce(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }): { x: number; }; reduce(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }, initialValue: { x: number; }): { x: number; }; reduce(callbackfn: (previousValue: U, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }): { x: number; }; reduceRight(callbackfn: (previousValue: { x: number; }, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => { x: number; }, initialValue: { x: number; }): { x: number; }; reduceRight(callbackfn: (previousValue: U, currentValue: { x: number; }, currentIndex: number, array: { x: number; }[]) => U, initialValue: U): U; } +>items : { x: number; }[] + diff --git a/tests/baselines/reference/jsDeclarationsInterfaces.errors.txt b/tests/baselines/reference/jsDeclarationsInterfaces.errors.txt new file mode 100644 index 0000000000000..24ed71af90837 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsInterfaces.errors.txt @@ -0,0 +1,200 @@ +tests/cases/conformance/jsdoc/declarations/index.js(4,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(6,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(10,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(31,11): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(35,11): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(39,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(43,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(45,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(49,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(53,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(57,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(61,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(65,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(67,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(71,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(75,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(80,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(84,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(87,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(91,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(95,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(100,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(105,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(107,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(111,18): error TS8006: 'interface declarations' can only be used in a .ts file. +tests/cases/conformance/jsdoc/declarations/index.js(115,18): error TS8006: 'interface declarations' can only be used in a .ts file. + + +==== tests/cases/conformance/jsdoc/declarations/index.js (26 errors) ==== + // Pretty much all of this should be an error, (since interfaces are forbidden in js), + // but we should be able to synthesize declarations from the symbols regardless + + export interface A {} + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + + export interface B { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + cat: string; + } + + export interface C { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + field: T & U; + optionalField?: T; + readonly readonlyField: T & U; + readonly readonlyOptionalField?: U; + (): number; + (x: T): U; + (x: Q): T & Q; + + new (): string; + new (x: T): U; + new (x: Q): T & Q; + + method(): number; + method(a: T & Q): Q & number; + method(a?: number): number; + method(...args: any[]): number; + + optMethod?(): number; + } + + interface G {} + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + + export { G }; + + interface HH {} + ~~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + + export { HH as H }; + + export interface I {} + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + export { I as II }; + + export { J as JJ }; + export interface J {} + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + + export interface K extends I,J { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + x: string; + } + + export interface L extends K { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + y: string; + } + + export interface M { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + field: T; + } + + export interface N extends M { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + other: U; + } + + export interface O { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: string]: string; + } + + export interface P extends O {} + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + + export interface Q extends O { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: string]: "ok"; + } + + export interface R extends O { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: number]: "ok"; + } + + export interface S extends O { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: string]: "ok"; + [idx: number]: never; + } + + export interface T { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: number]: string; + } + + export interface U extends T {} + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + + + export interface V extends T { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: string]: string; + } + + export interface W extends T { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: number]: "ok"; + } + + export interface X extends T { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: string]: string; + [idx: number]: "ok"; + } + + export interface Y { + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: string]: {x: number}; + [idx: number]: {x: number, y: number}; + } + + export interface Z extends Y {} + ~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + + export interface AA extends Y { + ~~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: string]: {x: number, y: number}; + } + + export interface BB extends Y { + ~~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: number]: {x: 0, y: 0}; + } + + export interface CC extends Y { + ~~ +!!! error TS8006: 'interface declarations' can only be used in a .ts file. + [idx: string]: {x: number, y: number}; + [idx: number]: {x: 0, y: 0}; + } + \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsInterfaces.js b/tests/baselines/reference/jsDeclarationsInterfaces.js new file mode 100644 index 0000000000000..00e78c8286a88 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsInterfaces.js @@ -0,0 +1,235 @@ +//// [index.js] +// Pretty much all of this should be an error, (since interfaces are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export interface A {} + +export interface B { + cat: string; +} + +export interface C { + field: T & U; + optionalField?: T; + readonly readonlyField: T & U; + readonly readonlyOptionalField?: U; + (): number; + (x: T): U; + (x: Q): T & Q; + + new (): string; + new (x: T): U; + new (x: Q): T & Q; + + method(): number; + method(a: T & Q): Q & number; + method(a?: number): number; + method(...args: any[]): number; + + optMethod?(): number; +} + +interface G {} + +export { G }; + +interface HH {} + +export { HH as H }; + +export interface I {} +export { I as II }; + +export { J as JJ }; +export interface J {} + +export interface K extends I,J { + x: string; +} + +export interface L extends K { + y: string; +} + +export interface M { + field: T; +} + +export interface N extends M { + other: U; +} + +export interface O { + [idx: string]: string; +} + +export interface P extends O {} + +export interface Q extends O { + [idx: string]: "ok"; +} + +export interface R extends O { + [idx: number]: "ok"; +} + +export interface S extends O { + [idx: string]: "ok"; + [idx: number]: never; +} + +export interface T { + [idx: number]: string; +} + +export interface U extends T {} + + +export interface V extends T { + [idx: string]: string; +} + +export interface W extends T { + [idx: number]: "ok"; +} + +export interface X extends T { + [idx: string]: string; + [idx: number]: "ok"; +} + +export interface Y { + [idx: string]: {x: number}; + [idx: number]: {x: number, y: number}; +} + +export interface Z extends Y {} + +export interface AA extends Y { + [idx: string]: {x: number, y: number}; +} + +export interface BB extends Y { + [idx: number]: {x: 0, y: 0}; +} + +export interface CC extends Y { + [idx: string]: {x: number, y: number}; + [idx: number]: {x: 0, y: 0}; +} + + +//// [index.js] +"use strict"; +// Pretty much all of this should be an error, (since interfaces are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless +Object.defineProperty(exports, "__esModule", { value: true }); + + +//// [index.d.ts] +export interface A { +} +export interface B { + cat: string; +} +export interface C { + new (): string; + new (x: T_1): U_1; + new (x: Q_4): T_1 & Q_4; + (): number; + (x: T_1): U_1; + (x: Q_3): T_1 & Q_3; + field: T_1 & U_1; + optionalField?: T_1; + readonly readonlyField: T_1 & U_1; + readonly readonlyOptionalField?: U_1; + method(): number; + method(a: T_1 & Q_2): Q_2 & number; + method(a?: number): number; + method(...args: any[]): number; + optMethod?(): number; +} +export interface I { +} +export interface J { +} +export interface K extends I, J { + x: string; +} +export interface L extends K { + y: string; +} +export interface M { + field: T_1; +} +export interface N extends M { + other: U_1; +} +export interface O { + [idx: string]: string; +} +export interface P extends O { +} +export interface Q extends O { + [idx: string]: "ok"; +} +export interface R extends O { + [idx: number]: "ok"; +} +export interface S extends O { + [idx: string]: "ok"; + [idx: number]: never; +} +export interface T { + [idx: number]: string; +} +export interface U extends T { +} +export interface V extends T { + [idx: string]: string; +} +export interface W extends T { + [idx: number]: "ok"; +} +export interface X extends T { + [idx: string]: string; + [idx: number]: "ok"; +} +export interface Y { + [idx: string]: { + x: number; + }; + [idx: number]: { + x: number; + y: number; + }; +} +export interface Z extends Y { +} +export interface AA extends Y { + [idx: string]: { + x: number; + y: number; + }; +} +export interface BB extends Y { + [idx: number]: { + x: 0; + y: 0; + }; +} +export interface CC extends Y { + [idx: string]: { + x: number; + y: number; + }; + [idx: number]: { + x: 0; + y: 0; + }; +} +export interface G { +} +interface HH { +} +export { HH as H, I as II, J as JJ }; diff --git a/tests/baselines/reference/jsDeclarationsInterfaces.symbols b/tests/baselines/reference/jsDeclarationsInterfaces.symbols new file mode 100644 index 0000000000000..d042802f42229 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsInterfaces.symbols @@ -0,0 +1,280 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// Pretty much all of this should be an error, (since interfaces are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export interface A {} +>A : Symbol(A, Decl(index.js, 0, 0)) + +export interface B { +>B : Symbol(B, Decl(index.js, 3, 21)) + + cat: string; +>cat : Symbol(B.cat, Decl(index.js, 5, 20)) +} + +export interface C { +>C : Symbol(C, Decl(index.js, 7, 1)) +>T : Symbol(T, Decl(index.js, 9, 19)) +>U : Symbol(U, Decl(index.js, 9, 21)) + + field: T & U; +>field : Symbol(C.field, Decl(index.js, 9, 26)) +>T : Symbol(T, Decl(index.js, 9, 19)) +>U : Symbol(U, Decl(index.js, 9, 21)) + + optionalField?: T; +>optionalField : Symbol(C.optionalField, Decl(index.js, 10, 17)) +>T : Symbol(T, Decl(index.js, 9, 19)) + + readonly readonlyField: T & U; +>readonlyField : Symbol(C.readonlyField, Decl(index.js, 11, 22)) +>T : Symbol(T, Decl(index.js, 9, 19)) +>U : Symbol(U, Decl(index.js, 9, 21)) + + readonly readonlyOptionalField?: U; +>readonlyOptionalField : Symbol(C.readonlyOptionalField, Decl(index.js, 12, 34)) +>U : Symbol(U, Decl(index.js, 9, 21)) + + (): number; + (x: T): U; +>x : Symbol(x, Decl(index.js, 15, 5)) +>T : Symbol(T, Decl(index.js, 9, 19)) +>U : Symbol(U, Decl(index.js, 9, 21)) + + (x: Q): T & Q; +>Q : Symbol(Q, Decl(index.js, 16, 5)) +>x : Symbol(x, Decl(index.js, 16, 8)) +>Q : Symbol(Q, Decl(index.js, 16, 5)) +>T : Symbol(T, Decl(index.js, 9, 19)) +>Q : Symbol(Q, Decl(index.js, 16, 5)) + + new (): string; + new (x: T): U; +>x : Symbol(x, Decl(index.js, 19, 9)) +>T : Symbol(T, Decl(index.js, 9, 19)) +>U : Symbol(U, Decl(index.js, 9, 21)) + + new (x: Q): T & Q; +>Q : Symbol(Q, Decl(index.js, 20, 9)) +>x : Symbol(x, Decl(index.js, 20, 12)) +>Q : Symbol(Q, Decl(index.js, 20, 9)) +>T : Symbol(T, Decl(index.js, 9, 19)) +>Q : Symbol(Q, Decl(index.js, 20, 9)) + + method(): number; +>method : Symbol(C.method, Decl(index.js, 20, 25), Decl(index.js, 22, 33), Decl(index.js, 23, 36), Decl(index.js, 24, 31)) +>Q : Symbol(Q, Decl(index.js, 22, 11)) + + method(a: T & Q): Q & number; +>method : Symbol(C.method, Decl(index.js, 20, 25), Decl(index.js, 22, 33), Decl(index.js, 23, 36), Decl(index.js, 24, 31)) +>Q : Symbol(Q, Decl(index.js, 23, 11)) +>a : Symbol(a, Decl(index.js, 23, 14)) +>T : Symbol(T, Decl(index.js, 9, 19)) +>Q : Symbol(Q, Decl(index.js, 23, 11)) +>Q : Symbol(Q, Decl(index.js, 23, 11)) + + method(a?: number): number; +>method : Symbol(C.method, Decl(index.js, 20, 25), Decl(index.js, 22, 33), Decl(index.js, 23, 36), Decl(index.js, 24, 31)) +>a : Symbol(a, Decl(index.js, 24, 11)) + + method(...args: any[]): number; +>method : Symbol(C.method, Decl(index.js, 20, 25), Decl(index.js, 22, 33), Decl(index.js, 23, 36), Decl(index.js, 24, 31)) +>args : Symbol(args, Decl(index.js, 25, 11)) + + optMethod?(): number; +>optMethod : Symbol(C.optMethod, Decl(index.js, 25, 35)) +} + +interface G {} +>G : Symbol(G, Decl(index.js, 28, 1)) + +export { G }; +>G : Symbol(G, Decl(index.js, 32, 8)) + +interface HH {} +>HH : Symbol(HH, Decl(index.js, 32, 13)) + +export { HH as H }; +>HH : Symbol(HH, Decl(index.js, 32, 13)) +>H : Symbol(H, Decl(index.js, 36, 8)) + +export interface I {} +>I : Symbol(I, Decl(index.js, 36, 19)) + +export { I as II }; +>I : Symbol(I, Decl(index.js, 36, 19)) +>II : Symbol(II, Decl(index.js, 39, 8)) + +export { J as JJ }; +>J : Symbol(J, Decl(index.js, 41, 19)) +>JJ : Symbol(JJ, Decl(index.js, 41, 8)) + +export interface J {} +>J : Symbol(J, Decl(index.js, 41, 19)) + +export interface K extends I,J { +>K : Symbol(K, Decl(index.js, 42, 21)) +>I : Symbol(I, Decl(index.js, 36, 19)) +>J : Symbol(J, Decl(index.js, 41, 19)) + + x: string; +>x : Symbol(K.x, Decl(index.js, 44, 32)) +} + +export interface L extends K { +>L : Symbol(L, Decl(index.js, 46, 1)) +>K : Symbol(K, Decl(index.js, 42, 21)) + + y: string; +>y : Symbol(L.y, Decl(index.js, 48, 30)) +} + +export interface M { +>M : Symbol(M, Decl(index.js, 50, 1)) +>T : Symbol(T, Decl(index.js, 52, 19)) + + field: T; +>field : Symbol(M.field, Decl(index.js, 52, 23)) +>T : Symbol(T, Decl(index.js, 52, 19)) +} + +export interface N extends M { +>N : Symbol(N, Decl(index.js, 54, 1)) +>U : Symbol(U, Decl(index.js, 56, 19)) +>M : Symbol(M, Decl(index.js, 50, 1)) +>U : Symbol(U, Decl(index.js, 56, 19)) + + other: U; +>other : Symbol(N.other, Decl(index.js, 56, 36)) +>U : Symbol(U, Decl(index.js, 56, 19)) +} + +export interface O { +>O : Symbol(O, Decl(index.js, 58, 1)) + + [idx: string]: string; +>idx : Symbol(idx, Decl(index.js, 61, 5)) +} + +export interface P extends O {} +>P : Symbol(P, Decl(index.js, 62, 1)) +>O : Symbol(O, Decl(index.js, 58, 1)) + +export interface Q extends O { +>Q : Symbol(Q, Decl(index.js, 64, 31)) +>O : Symbol(O, Decl(index.js, 58, 1)) + + [idx: string]: "ok"; +>idx : Symbol(idx, Decl(index.js, 67, 5)) +} + +export interface R extends O { +>R : Symbol(R, Decl(index.js, 68, 1)) +>O : Symbol(O, Decl(index.js, 58, 1)) + + [idx: number]: "ok"; +>idx : Symbol(idx, Decl(index.js, 71, 5)) +} + +export interface S extends O { +>S : Symbol(S, Decl(index.js, 72, 1)) +>O : Symbol(O, Decl(index.js, 58, 1)) + + [idx: string]: "ok"; +>idx : Symbol(idx, Decl(index.js, 75, 5)) + + [idx: number]: never; +>idx : Symbol(idx, Decl(index.js, 76, 5)) +} + +export interface T { +>T : Symbol(T, Decl(index.js, 77, 1)) + + [idx: number]: string; +>idx : Symbol(idx, Decl(index.js, 80, 5)) +} + +export interface U extends T {} +>U : Symbol(U, Decl(index.js, 81, 1)) +>T : Symbol(T, Decl(index.js, 77, 1)) + + +export interface V extends T { +>V : Symbol(V, Decl(index.js, 83, 31)) +>T : Symbol(T, Decl(index.js, 77, 1)) + + [idx: string]: string; +>idx : Symbol(idx, Decl(index.js, 87, 5)) +} + +export interface W extends T { +>W : Symbol(W, Decl(index.js, 88, 1)) +>T : Symbol(T, Decl(index.js, 77, 1)) + + [idx: number]: "ok"; +>idx : Symbol(idx, Decl(index.js, 91, 5)) +} + +export interface X extends T { +>X : Symbol(X, Decl(index.js, 92, 1)) +>T : Symbol(T, Decl(index.js, 77, 1)) + + [idx: string]: string; +>idx : Symbol(idx, Decl(index.js, 95, 5)) + + [idx: number]: "ok"; +>idx : Symbol(idx, Decl(index.js, 96, 5)) +} + +export interface Y { +>Y : Symbol(Y, Decl(index.js, 97, 1)) + + [idx: string]: {x: number}; +>idx : Symbol(idx, Decl(index.js, 100, 5)) +>x : Symbol(x, Decl(index.js, 100, 20)) + + [idx: number]: {x: number, y: number}; +>idx : Symbol(idx, Decl(index.js, 101, 5)) +>x : Symbol(x, Decl(index.js, 101, 20)) +>y : Symbol(y, Decl(index.js, 101, 30)) +} + +export interface Z extends Y {} +>Z : Symbol(Z, Decl(index.js, 102, 1)) +>Y : Symbol(Y, Decl(index.js, 97, 1)) + +export interface AA extends Y { +>AA : Symbol(AA, Decl(index.js, 104, 31)) +>Y : Symbol(Y, Decl(index.js, 97, 1)) + + [idx: string]: {x: number, y: number}; +>idx : Symbol(idx, Decl(index.js, 107, 5)) +>x : Symbol(x, Decl(index.js, 107, 20)) +>y : Symbol(y, Decl(index.js, 107, 30)) +} + +export interface BB extends Y { +>BB : Symbol(BB, Decl(index.js, 108, 1)) +>Y : Symbol(Y, Decl(index.js, 97, 1)) + + [idx: number]: {x: 0, y: 0}; +>idx : Symbol(idx, Decl(index.js, 111, 5)) +>x : Symbol(x, Decl(index.js, 111, 20)) +>y : Symbol(y, Decl(index.js, 111, 25)) +} + +export interface CC extends Y { +>CC : Symbol(CC, Decl(index.js, 112, 1)) +>Y : Symbol(Y, Decl(index.js, 97, 1)) + + [idx: string]: {x: number, y: number}; +>idx : Symbol(idx, Decl(index.js, 115, 5)) +>x : Symbol(x, Decl(index.js, 115, 20)) +>y : Symbol(y, Decl(index.js, 115, 30)) + + [idx: number]: {x: 0, y: 0}; +>idx : Symbol(idx, Decl(index.js, 116, 5)) +>x : Symbol(x, Decl(index.js, 116, 20)) +>y : Symbol(y, Decl(index.js, 116, 25)) +} + diff --git a/tests/baselines/reference/jsDeclarationsInterfaces.types b/tests/baselines/reference/jsDeclarationsInterfaces.types new file mode 100644 index 0000000000000..2e7e1576cc0db --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsInterfaces.types @@ -0,0 +1,189 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +// Pretty much all of this should be an error, (since interfaces are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export interface A {} + +export interface B { + cat: string; +>cat : string +} + +export interface C { + field: T & U; +>field : T & U + + optionalField?: T; +>optionalField : T + + readonly readonlyField: T & U; +>readonlyField : T & U + + readonly readonlyOptionalField?: U; +>readonlyOptionalField : U + + (): number; + (x: T): U; +>x : T + + (x: Q): T & Q; +>x : Q + + new (): string; + new (x: T): U; +>x : T + + new (x: Q): T & Q; +>x : Q + + method(): number; +>method : { (): number; (a: T & Q): Q & number; (a?: number): number; (...args: any[]): number; } + + method(a: T & Q): Q & number; +>method : { (): number; (a: T & Q): Q & number; (a?: number): number; (...args: any[]): number; } +>a : T & Q + + method(a?: number): number; +>method : { (): number; (a: T & Q): Q & number; (a?: number): number; (...args: any[]): number; } +>a : number + + method(...args: any[]): number; +>method : { (): number; (a: T & Q): Q & number; (a?: number): number; (...args: any[]): number; } +>args : any[] + + optMethod?(): number; +>optMethod : () => number +} + +interface G {} + +export { G }; +>G : any + +interface HH {} + +export { HH as H }; +>HH : any +>H : any + +export interface I {} +export { I as II }; +>I : any +>II : any + +export { J as JJ }; +>J : any +>JJ : any + +export interface J {} + +export interface K extends I,J { + x: string; +>x : string +} + +export interface L extends K { + y: string; +>y : string +} + +export interface M { + field: T; +>field : T +} + +export interface N extends M { + other: U; +>other : U +} + +export interface O { + [idx: string]: string; +>idx : string +} + +export interface P extends O {} + +export interface Q extends O { + [idx: string]: "ok"; +>idx : string +} + +export interface R extends O { + [idx: number]: "ok"; +>idx : number +} + +export interface S extends O { + [idx: string]: "ok"; +>idx : string + + [idx: number]: never; +>idx : number +} + +export interface T { + [idx: number]: string; +>idx : number +} + +export interface U extends T {} + + +export interface V extends T { + [idx: string]: string; +>idx : string +} + +export interface W extends T { + [idx: number]: "ok"; +>idx : number +} + +export interface X extends T { + [idx: string]: string; +>idx : string + + [idx: number]: "ok"; +>idx : number +} + +export interface Y { + [idx: string]: {x: number}; +>idx : string +>x : number + + [idx: number]: {x: number, y: number}; +>idx : number +>x : number +>y : number +} + +export interface Z extends Y {} + +export interface AA extends Y { + [idx: string]: {x: number, y: number}; +>idx : string +>x : number +>y : number +} + +export interface BB extends Y { + [idx: number]: {x: 0, y: 0}; +>idx : number +>x : 0 +>y : 0 +} + +export interface CC extends Y { + [idx: string]: {x: number, y: number}; +>idx : string +>x : number +>y : number + + [idx: number]: {x: 0, y: 0}; +>idx : number +>x : 0 +>y : 0 +} + diff --git a/tests/baselines/reference/jsDeclarationsJson.js b/tests/baselines/reference/jsDeclarationsJson.js new file mode 100644 index 0000000000000..2cebc7b583a8f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsJson.js @@ -0,0 +1,66 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsJson.ts] //// + +//// [index.js] +const j = require("./obj.json"); +module.exports = j; +//// [obj.json] +{ + "x": 12, + "y": 12, + "obj": { + "items": [{"x": 12}, {"x": 12, "y": 12}, {"x": 0}, {"x": -1, "err": true}] + } +} + +//// [obj.json] +{ + "x": 12, + "y": 12, + "obj": { + "items": [{ "x": 12 }, { "x": 12, "y": 12 }, { "x": 0 }, { "x": -1, "err": true }] + } +} +//// [index.js] +var j = require("./obj.json"); +module.exports = j; + + +//// [obj.d.ts] +export declare const x: number; +export declare const y: number; +export declare namespace obj { + export const items: ({ + "x": number; + "y"?: undefined; + "err"?: undefined; + } | { + "x": number; + "y": number; + "err"?: undefined; + } | { + "x": number; + "err": boolean; + "y"?: undefined; + })[]; +} +//// [index.d.ts] +export = j; +declare const j: { + "x": number; + "y": number; + "obj": { + "items": ({ + "x": number; + "y"?: undefined; + "err"?: undefined; + } | { + "x": number; + "y": number; + "err"?: undefined; + } | { + "x": number; + "err": boolean; + "y"?: undefined; + })[]; + }; +}; diff --git a/tests/baselines/reference/jsDeclarationsJson.symbols b/tests/baselines/reference/jsDeclarationsJson.symbols new file mode 100644 index 0000000000000..9e276decbc6b5 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsJson.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const j = require("./obj.json"); +>j : Symbol(j, Decl(index.js, 0, 5)) +>require : Symbol(require) +>"./obj.json" : Symbol("tests/cases/conformance/jsdoc/declarations/obj", Decl(obj.json, 0, 0)) + +module.exports = j; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 0, 32)) +>exports : Symbol(export=, Decl(index.js, 0, 32)) +>j : Symbol(j, Decl(index.js, 0, 5)) + +=== tests/cases/conformance/jsdoc/declarations/obj.json === +{ + "x": 12, +>"x" : Symbol("x", Decl(obj.json, 0, 1)) + + "y": 12, +>"y" : Symbol("y", Decl(obj.json, 1, 12)) + + "obj": { +>"obj" : Symbol("obj", Decl(obj.json, 2, 12)) + + "items": [{"x": 12}, {"x": 12, "y": 12}, {"x": 0}, {"x": -1, "err": true}] +>"items" : Symbol("items", Decl(obj.json, 3, 12)) +>"x" : Symbol("x", Decl(obj.json, 4, 19)) +>"x" : Symbol("x", Decl(obj.json, 4, 30)) +>"y" : Symbol("y", Decl(obj.json, 4, 38)) +>"x" : Symbol("x", Decl(obj.json, 4, 50)) +>"x" : Symbol("x", Decl(obj.json, 4, 60)) +>"err" : Symbol("err", Decl(obj.json, 4, 68)) + } +} diff --git a/tests/baselines/reference/jsDeclarationsJson.types b/tests/baselines/reference/jsDeclarationsJson.types new file mode 100644 index 0000000000000..aaab20ac36a2e --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsJson.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const j = require("./obj.json"); +>j : { "x": number; "y": number; "obj": { "items": ({ "x": number; "y"?: undefined; "err"?: undefined; } | { "x": number; "y": number; "err"?: undefined; } | { "x": number; "err": boolean; "y"?: undefined; })[]; }; } +>require("./obj.json") : { "x": number; "y": number; "obj": { "items": ({ "x": number; } | { "x": number; "y": number; } | { "x": number; "err": boolean; })[]; }; } +>require : any +>"./obj.json" : "./obj.json" + +module.exports = j; +>module.exports = j : { "x": number; "y": number; "obj": { "items": ({ "x": number; "y"?: undefined; "err"?: undefined; } | { "x": number; "y": number; "err"?: undefined; } | { "x": number; "err": boolean; "y"?: undefined; })[]; }; } +>module.exports : { "x": number; "y": number; "obj": { "items": ({ "x": number; "y"?: undefined; "err"?: undefined; } | { "x": number; "y": number; "err"?: undefined; } | { "x": number; "err": boolean; "y"?: undefined; })[]; }; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { "x": number; "y": number; "obj": { "items": ({ "x": number; "y"?: undefined; "err"?: undefined; } | { "x": number; "y": number; "err"?: undefined; } | { "x": number; "err": boolean; "y"?: undefined; })[]; }; }; } +>exports : { "x": number; "y": number; "obj": { "items": ({ "x": number; "y"?: undefined; "err"?: undefined; } | { "x": number; "y": number; "err"?: undefined; } | { "x": number; "err": boolean; "y"?: undefined; })[]; }; } +>j : { "x": number; "y": number; "obj": { "items": ({ "x": number; "y"?: undefined; "err"?: undefined; } | { "x": number; "y": number; "err"?: undefined; } | { "x": number; "err": boolean; "y"?: undefined; })[]; }; } + +=== tests/cases/conformance/jsdoc/declarations/obj.json === +{ +>{ "x": 12, "y": 12, "obj": { "items": [{"x": 12}, {"x": 12, "y": 12}, {"x": 0}, {"x": -1, "err": true}] }} : { "x": number; "y": number; "obj": { "items": ({ "x": number; } | { "x": number; "y": number; } | { "x": number; "err": boolean; })[]; }; } + + "x": 12, +>"x" : number +>12 : 12 + + "y": 12, +>"y" : number +>12 : 12 + + "obj": { +>"obj" : { "items": ({ "x": number; } | { "x": number; "y": number; } | { "x": number; "err": boolean; })[]; } +>{ "items": [{"x": 12}, {"x": 12, "y": 12}, {"x": 0}, {"x": -1, "err": true}] } : { "items": ({ "x": number; } | { "x": number; "y": number; } | { "x": number; "err": boolean; })[]; } + + "items": [{"x": 12}, {"x": 12, "y": 12}, {"x": 0}, {"x": -1, "err": true}] +>"items" : ({ "x": number; } | { "x": number; "y": number; } | { "x": number; "err": boolean; })[] +>[{"x": 12}, {"x": 12, "y": 12}, {"x": 0}, {"x": -1, "err": true}] : ({ "x": number; } | { "x": number; "y": number; } | { "x": number; "err": boolean; })[] +>{"x": 12} : { "x": number; } +>"x" : number +>12 : 12 +>{"x": 12, "y": 12} : { "x": number; "y": number; } +>"x" : number +>12 : 12 +>"y" : number +>12 : 12 +>{"x": 0} : { "x": number; } +>"x" : number +>0 : 0 +>{"x": -1, "err": true} : { "x": number; "err": boolean; } +>"x" : number +>-1 : -1 +>1 : 1 +>"err" : boolean +>true : true + } +} diff --git a/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.js b/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.js new file mode 100644 index 0000000000000..75e7c37bd8db2 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.js @@ -0,0 +1,70 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsMultipleExportFromMerge.ts] //// + +//// [items.js] +export const a = 1; +export const b = 2; +export const c = 3; + +//// [justone.js] +export { a, b, c } from "./items"; + +//// [two.js] +export { a } from "./items"; +export { b, c } from "./items"; + +//// [multiple.js] +export {a, b} from "./items"; +export {a as aa} from "./two"; +export {b as bb} from "./two"; +export {c} from "./two" +export {c as cc} from "./items"; + + +//// [items.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.a = 1; +exports.b = 2; +exports.c = 3; +//// [justone.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var items_1 = require("./items"); +exports.a = items_1.a; +exports.b = items_1.b; +exports.c = items_1.c; +//// [two.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var items_1 = require("./items"); +exports.a = items_1.a; +var items_2 = require("./items"); +exports.b = items_2.b; +exports.c = items_2.c; +//// [multiple.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var items_1 = require("./items"); +exports.a = items_1.a; +exports.b = items_1.b; +var two_1 = require("./two"); +exports.aa = two_1.a; +var two_2 = require("./two"); +exports.bb = two_2.b; +var two_3 = require("./two"); +exports.c = two_3.c; +var items_2 = require("./items"); +exports.cc = items_2.c; + + +//// [items.d.ts] +export const a: 1; +export const b: 2; +export const c: 3; +//// [justone.d.ts] +export { a, b, c } from "./items"; +//// [two.d.ts] +export { a, b, c } from "./items"; +//// [multiple.d.ts] +export { a, b, c as cc } from "./items"; +export { a as aa, b as bb, c } from "./two"; diff --git a/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.symbols b/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.symbols new file mode 100644 index 0000000000000..63168d91f55ff --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.symbols @@ -0,0 +1,44 @@ +=== tests/cases/conformance/jsdoc/declarations/items.js === +export const a = 1; +>a : Symbol(a, Decl(items.js, 0, 12)) + +export const b = 2; +>b : Symbol(b, Decl(items.js, 1, 12)) + +export const c = 3; +>c : Symbol(c, Decl(items.js, 2, 12)) + +=== tests/cases/conformance/jsdoc/declarations/justone.js === +export { a, b, c } from "./items"; +>a : Symbol(a, Decl(justone.js, 0, 8)) +>b : Symbol(b, Decl(justone.js, 0, 11)) +>c : Symbol(c, Decl(justone.js, 0, 14)) + +=== tests/cases/conformance/jsdoc/declarations/two.js === +export { a } from "./items"; +>a : Symbol(a, Decl(two.js, 0, 8)) + +export { b, c } from "./items"; +>b : Symbol(b, Decl(two.js, 1, 8)) +>c : Symbol(c, Decl(two.js, 1, 11)) + +=== tests/cases/conformance/jsdoc/declarations/multiple.js === +export {a, b} from "./items"; +>a : Symbol(a, Decl(multiple.js, 0, 8)) +>b : Symbol(b, Decl(multiple.js, 0, 10)) + +export {a as aa} from "./two"; +>a : Symbol(a, Decl(two.js, 0, 8)) +>aa : Symbol(aa, Decl(multiple.js, 1, 8)) + +export {b as bb} from "./two"; +>b : Symbol(b, Decl(two.js, 1, 8)) +>bb : Symbol(bb, Decl(multiple.js, 2, 8)) + +export {c} from "./two" +>c : Symbol(c, Decl(multiple.js, 3, 8)) + +export {c as cc} from "./items"; +>c : Symbol(c, Decl(items.js, 2, 12)) +>cc : Symbol(cc, Decl(multiple.js, 4, 8)) + diff --git a/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.types b/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.types new file mode 100644 index 0000000000000..741ad48205749 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsMultipleExportFromMerge.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/jsdoc/declarations/items.js === +export const a = 1; +>a : 1 +>1 : 1 + +export const b = 2; +>b : 2 +>2 : 2 + +export const c = 3; +>c : 3 +>3 : 3 + +=== tests/cases/conformance/jsdoc/declarations/justone.js === +export { a, b, c } from "./items"; +>a : 1 +>b : 2 +>c : 3 + +=== tests/cases/conformance/jsdoc/declarations/two.js === +export { a } from "./items"; +>a : 1 + +export { b, c } from "./items"; +>b : 2 +>c : 3 + +=== tests/cases/conformance/jsdoc/declarations/multiple.js === +export {a, b} from "./items"; +>a : 1 +>b : 2 + +export {a as aa} from "./two"; +>a : 1 +>aa : 1 + +export {b as bb} from "./two"; +>b : 2 +>bb : 2 + +export {c} from "./two" +>c : 3 + +export {c as cc} from "./items"; +>c : 3 +>cc : 3 + diff --git a/tests/baselines/reference/jsDeclarationsPackageJson.js b/tests/baselines/reference/jsDeclarationsPackageJson.js new file mode 100644 index 0000000000000..66da073d33882 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsPackageJson.js @@ -0,0 +1,135 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsPackageJson.ts] //// + +//// [index.js] +const j = require("./package.json"); +module.exports = j; +//// [package.json] +{ + "name": "pkg", + "version": "0.1.0", + "description": "A package", + "main": "./dist/index.js", + "bin": { + "cli": "./bin/cli.js", + }, + "engines": { + "node": ">=0" + }, + "scripts": { + "scriptname": "run && run again", + }, + "devDependencies": { + "@ns/dep": "0.1.2", + }, + "dependencies": { + "dep": "1.2.3", + }, + "repository": "microsoft/TypeScript", + "keywords": [ + "kw" + ], + "author": "Auth", + "license": "See Licensce", + "homepage": "https://site", + "config": { + "o": ["a"] + } +} + + +//// [package.json] +{ + "name": "pkg", + "version": "0.1.0", + "description": "A package", + "main": "./dist/index.js", + "bin": { + "cli": "./bin/cli.js" + }, + "engines": { + "node": ">=0" + }, + "scripts": { + "scriptname": "run && run again" + }, + "devDependencies": { + "@ns/dep": "0.1.2" + }, + "dependencies": { + "dep": "1.2.3" + }, + "repository": "microsoft/TypeScript", + "keywords": [ + "kw" + ], + "author": "Auth", + "license": "See Licensce", + "homepage": "https://site", + "config": { + "o": ["a"] + } +} +//// [index.js] +var j = require("./package.json"); +module.exports = j; + + +//// [package.d.ts] +export declare const name: string; +export declare const version: string; +export declare const description: string; +export declare const main: string; +export declare namespace bin { + export const cli: string; +} +export declare namespace engines { + export const node: string; +} +export declare namespace scripts { + export const scriptname: string; +} +export declare const devDependencies: { + "@ns/dep": string; +}; +export declare namespace dependencies { + export const dep: string; +} +export declare const repository: string; +export declare const keywords: string[]; +export declare const author: string; +export declare const license: string; +export declare const homepage: string; +export declare namespace config { + export const o: string[]; +} +//// [index.d.ts] +export = j; +declare const j: { + "name": string; + "version": string; + "description": string; + "main": string; + "bin": { + "cli": string; + }; + "engines": { + "node": string; + }; + "scripts": { + "scriptname": string; + }; + "devDependencies": { + "@ns/dep": string; + }; + "dependencies": { + "dep": string; + }; + "repository": string; + "keywords": string[]; + "author": string; + "license": string; + "homepage": string; + "config": { + "o": string[]; + }; +}; diff --git a/tests/baselines/reference/jsDeclarationsPackageJson.symbols b/tests/baselines/reference/jsDeclarationsPackageJson.symbols new file mode 100644 index 0000000000000..7f09a886bab0a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsPackageJson.symbols @@ -0,0 +1,86 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const j = require("./package.json"); +>j : Symbol(j, Decl(index.js, 0, 5)) +>require : Symbol(require) +>"./package.json" : Symbol("tests/cases/conformance/jsdoc/declarations/package", Decl(package.json, 0, 0)) + +module.exports = j; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 0, 36)) +>exports : Symbol(export=, Decl(index.js, 0, 36)) +>j : Symbol(j, Decl(index.js, 0, 5)) + +=== tests/cases/conformance/jsdoc/declarations/package.json === +{ + "name": "pkg", +>"name" : Symbol("name", Decl(package.json, 0, 1)) + + "version": "0.1.0", +>"version" : Symbol("version", Decl(package.json, 1, 18)) + + "description": "A package", +>"description" : Symbol("description", Decl(package.json, 2, 23)) + + "main": "./dist/index.js", +>"main" : Symbol("main", Decl(package.json, 3, 31)) + + "bin": { +>"bin" : Symbol("bin", Decl(package.json, 4, 30)) + + "cli": "./bin/cli.js", +>"cli" : Symbol("cli", Decl(package.json, 5, 12)) + + }, + "engines": { +>"engines" : Symbol("engines", Decl(package.json, 7, 6)) + + "node": ">=0" +>"node" : Symbol("node", Decl(package.json, 8, 16)) + + }, + "scripts": { +>"scripts" : Symbol("scripts", Decl(package.json, 10, 6)) + + "scriptname": "run && run again", +>"scriptname" : Symbol("scriptname", Decl(package.json, 11, 16)) + + }, + "devDependencies": { +>"devDependencies" : Symbol("devDependencies", Decl(package.json, 13, 6)) + + "@ns/dep": "0.1.2", +>"@ns/dep" : Symbol("@ns/dep", Decl(package.json, 14, 24)) + + }, + "dependencies": { +>"dependencies" : Symbol("dependencies", Decl(package.json, 16, 6)) + + "dep": "1.2.3", +>"dep" : Symbol("dep", Decl(package.json, 17, 21)) + + }, + "repository": "microsoft/TypeScript", +>"repository" : Symbol("repository", Decl(package.json, 19, 6)) + + "keywords": [ +>"keywords" : Symbol("keywords", Decl(package.json, 20, 41)) + + "kw" + ], + "author": "Auth", +>"author" : Symbol("author", Decl(package.json, 23, 6)) + + "license": "See Licensce", +>"license" : Symbol("license", Decl(package.json, 24, 21)) + + "homepage": "https://site", +>"homepage" : Symbol("homepage", Decl(package.json, 25, 30)) + + "config": { +>"config" : Symbol("config", Decl(package.json, 26, 31)) + + "o": ["a"] +>"o" : Symbol("o", Decl(package.json, 27, 15)) + } +} + diff --git a/tests/baselines/reference/jsDeclarationsPackageJson.types b/tests/baselines/reference/jsDeclarationsPackageJson.types new file mode 100644 index 0000000000000..c0b34509fcaf8 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsPackageJson.types @@ -0,0 +1,114 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const j = require("./package.json"); +>j : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; } +>require("./package.json") : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; } +>require : any +>"./package.json" : "./package.json" + +module.exports = j; +>module.exports = j : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; } +>module.exports : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; }; } +>exports : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; } +>j : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; } + +=== tests/cases/conformance/jsdoc/declarations/package.json === +{ +>{ "name": "pkg", "version": "0.1.0", "description": "A package", "main": "./dist/index.js", "bin": { "cli": "./bin/cli.js", }, "engines": { "node": ">=0" }, "scripts": { "scriptname": "run && run again", }, "devDependencies": { "@ns/dep": "0.1.2", }, "dependencies": { "dep": "1.2.3", }, "repository": "microsoft/TypeScript", "keywords": [ "kw" ], "author": "Auth", "license": "See Licensce", "homepage": "https://site", "config": { "o": ["a"] }} : { "name": string; "version": string; "description": string; "main": string; "bin": { "cli": string; }; "engines": { "node": string; }; "scripts": { "scriptname": string; }; "devDependencies": { "@ns/dep": string; }; "dependencies": { "dep": string; }; "repository": string; "keywords": string[]; "author": string; "license": string; "homepage": string; "config": { "o": string[]; }; } + + "name": "pkg", +>"name" : string +>"pkg" : "pkg" + + "version": "0.1.0", +>"version" : string +>"0.1.0" : "0.1.0" + + "description": "A package", +>"description" : string +>"A package" : "A package" + + "main": "./dist/index.js", +>"main" : string +>"./dist/index.js" : "./dist/index.js" + + "bin": { +>"bin" : { "cli": string; } +>{ "cli": "./bin/cli.js", } : { "cli": string; } + + "cli": "./bin/cli.js", +>"cli" : string +>"./bin/cli.js" : "./bin/cli.js" + + }, + "engines": { +>"engines" : { "node": string; } +>{ "node": ">=0" } : { "node": string; } + + "node": ">=0" +>"node" : string +>">=0" : ">=0" + + }, + "scripts": { +>"scripts" : { "scriptname": string; } +>{ "scriptname": "run && run again", } : { "scriptname": string; } + + "scriptname": "run && run again", +>"scriptname" : string +>"run && run again" : "run && run again" + + }, + "devDependencies": { +>"devDependencies" : { "@ns/dep": string; } +>{ "@ns/dep": "0.1.2", } : { "@ns/dep": string; } + + "@ns/dep": "0.1.2", +>"@ns/dep" : string +>"0.1.2" : "0.1.2" + + }, + "dependencies": { +>"dependencies" : { "dep": string; } +>{ "dep": "1.2.3", } : { "dep": string; } + + "dep": "1.2.3", +>"dep" : string +>"1.2.3" : "1.2.3" + + }, + "repository": "microsoft/TypeScript", +>"repository" : string +>"microsoft/TypeScript" : "microsoft/TypeScript" + + "keywords": [ +>"keywords" : string[] +>[ "kw" ] : string[] + + "kw" +>"kw" : "kw" + + ], + "author": "Auth", +>"author" : string +>"Auth" : "Auth" + + "license": "See Licensce", +>"license" : string +>"See Licensce" : "See Licensce" + + "homepage": "https://site", +>"homepage" : string +>"https://site" : "https://site" + + "config": { +>"config" : { "o": string[]; } +>{ "o": ["a"] } : { "o": string[]; } + + "o": ["a"] +>"o" : string[] +>["a"] : string[] +>"a" : "a" + } +} + diff --git a/tests/baselines/reference/jsDeclarationsReexportAliases.js b/tests/baselines/reference/jsDeclarationsReexportAliases.js new file mode 100644 index 0000000000000..1d117661c5d80 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReexportAliases.js @@ -0,0 +1,38 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsReexportAliases.ts] //// + +//// [cls.js] +export default class Foo {} + +//// [usage.js] +import {default as Fooa} from "./cls"; + +export const x = new Fooa(); + +export {default as Foob} from "./cls"; + + +//// [cls.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +exports.default = Foo; +//// [usage.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var cls_1 = require("./cls"); +exports.x = new cls_1.default(); +var cls_2 = require("./cls"); +exports.Foob = cls_2.default; + + +//// [cls.d.ts] +export default class Foo { +} +//// [usage.d.ts] +export const x: Fooa; +export { default as Foob } from "./cls"; +import { default as Fooa } from "./cls"; diff --git a/tests/baselines/reference/jsDeclarationsReexportAliases.symbols b/tests/baselines/reference/jsDeclarationsReexportAliases.symbols new file mode 100644 index 0000000000000..c34e9b238f3d9 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReexportAliases.symbols @@ -0,0 +1,17 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +export default class Foo {} +>Foo : Symbol(Foo, Decl(cls.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/usage.js === +import {default as Fooa} from "./cls"; +>default : Symbol(Fooa, Decl(cls.js, 0, 0)) +>Fooa : Symbol(Fooa, Decl(usage.js, 0, 8)) + +export const x = new Fooa(); +>x : Symbol(x, Decl(usage.js, 2, 12)) +>Fooa : Symbol(Fooa, Decl(usage.js, 0, 8)) + +export {default as Foob} from "./cls"; +>default : Symbol(Fooa, Decl(cls.js, 0, 0)) +>Foob : Symbol(Foob, Decl(usage.js, 4, 8)) + diff --git a/tests/baselines/reference/jsDeclarationsReexportAliases.types b/tests/baselines/reference/jsDeclarationsReexportAliases.types new file mode 100644 index 0000000000000..b1f8d6c27aa4a --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReexportAliases.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +export default class Foo {} +>Foo : Foo + +=== tests/cases/conformance/jsdoc/declarations/usage.js === +import {default as Fooa} from "./cls"; +>default : typeof Fooa +>Fooa : typeof Fooa + +export const x = new Fooa(); +>x : Fooa +>new Fooa() : Fooa +>Fooa : typeof Fooa + +export {default as Foob} from "./cls"; +>default : typeof Fooa +>Foob : typeof Fooa + diff --git a/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.js b/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.js new file mode 100644 index 0000000000000..d00269b2658ec --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsReexportAliasesEsModuleInterop.ts] //// + +//// [cls.js] +class Foo {} +module.exports = Foo; + +//// [usage.js] +import {default as Fooa} from "./cls"; + +export const x = new Fooa(); + +export {default as Foob} from "./cls"; + + +//// [cls.js] +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +module.exports = Foo; +//// [usage.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var cls_1 = __importDefault(require("./cls")); +exports.x = new cls_1.default(); +var cls_2 = require("./cls"); +exports.Foob = cls_2.default; + + +//// [cls.d.ts] +export = Foo; +declare class Foo { +} +//// [usage.d.ts] +export const x: Fooa; +export { default as Foob } from "./cls"; +import { default as Fooa } from "./cls"; diff --git a/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.symbols b/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.symbols new file mode 100644 index 0000000000000..221e0bd0d0316 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +class Foo {} +>Foo : Symbol(Foo, Decl(cls.js, 0, 0)) + +module.exports = Foo; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/cls", Decl(cls.js, 0, 0)) +>module : Symbol(export=, Decl(cls.js, 0, 12)) +>exports : Symbol(export=, Decl(cls.js, 0, 12)) +>Foo : Symbol(Foo, Decl(cls.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/usage.js === +import {default as Fooa} from "./cls"; +>default : Symbol(export=, Decl(cls.js, 0, 12)) +>Fooa : Symbol(Fooa, Decl(usage.js, 0, 8)) + +export const x = new Fooa(); +>x : Symbol(x, Decl(usage.js, 2, 12)) +>Fooa : Symbol(Fooa, Decl(usage.js, 0, 8)) + +export {default as Foob} from "./cls"; +>default : Symbol(export=, Decl(cls.js, 0, 12)) +>Foob : Symbol(Foob, Decl(usage.js, 4, 8)) + diff --git a/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.types b/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.types new file mode 100644 index 0000000000000..a67829317806f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReexportAliasesEsModuleInterop.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/jsdoc/declarations/cls.js === +class Foo {} +>Foo : Foo + +module.exports = Foo; +>module.exports = Foo : typeof Foo +>module.exports : typeof Foo +>module : { "tests/cases/conformance/jsdoc/declarations/cls": typeof Foo; } +>exports : typeof Foo +>Foo : typeof Foo + +=== tests/cases/conformance/jsdoc/declarations/usage.js === +import {default as Fooa} from "./cls"; +>default : typeof Fooa +>Fooa : typeof Fooa + +export const x = new Fooa(); +>x : Fooa +>new Fooa() : Fooa +>Fooa : typeof Fooa + +export {default as Foob} from "./cls"; +>default : typeof Fooa +>Foob : typeof Fooa + diff --git a/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.js b/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.js new file mode 100644 index 0000000000000..95297733d9ec8 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.js @@ -0,0 +1,66 @@ +//// [index.js] +/** @type {?} */ +export const a = null; + +/** @type {*} */ +export const b = null; + +/** @type {string?} */ +export const c = null; + +/** @type {string=} */ +export const d = null; + +/** @type {string!} */ +export const e = null; + +/** @type {function(string, number): object} */ +export const f = null; + +/** @type {function(new: object, string, number)} */ +export const g = null; + +/** @type {Object.} */ +export const h = null; + + +//// [index.js] +"use strict"; +exports.__esModule = true; +/** @type {?} */ +exports.a = null; +/** @type {*} */ +exports.b = null; +/** @type {string?} */ +exports.c = null; +/** @type {string=} */ +exports.d = null; +/** @type {string!} */ +exports.e = null; +/** @type {function(string, number): object} */ +exports.f = null; +/** @type {function(new: object, string, number)} */ +exports.g = null; +/** @type {Object.} */ +exports.h = null; + + +//// [index.d.ts] +/** @type {?} */ +export const a: unknown; +/** @type {*} */ +export const b: any; +/** @type {string?} */ +export const c: string | null; +/** @type {string=} */ +export const d: string | undefined; +/** @type {string!} */ +export const e: string; +/** @type {function(string, number): object} */ +export const f: (arg0: string, arg1: number) => object; +/** @type {function(new: object, string, number)} */ +export const g: new (arg1: string, arg2: number) => object; +/** @type {Object.} */ +export const h: { + [x: string]: number; +}; diff --git a/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.symbols b/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.symbols new file mode 100644 index 0000000000000..1fd1a1ad329b4 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** @type {?} */ +export const a = null; +>a : Symbol(a, Decl(index.js, 1, 12)) + +/** @type {*} */ +export const b = null; +>b : Symbol(b, Decl(index.js, 4, 12)) + +/** @type {string?} */ +export const c = null; +>c : Symbol(c, Decl(index.js, 7, 12)) + +/** @type {string=} */ +export const d = null; +>d : Symbol(d, Decl(index.js, 10, 12)) + +/** @type {string!} */ +export const e = null; +>e : Symbol(e, Decl(index.js, 13, 12)) + +/** @type {function(string, number): object} */ +export const f = null; +>f : Symbol(f, Decl(index.js, 16, 12)) + +/** @type {function(new: object, string, number)} */ +export const g = null; +>g : Symbol(g, Decl(index.js, 19, 12)) + +/** @type {Object.} */ +export const h = null; +>h : Symbol(h, Decl(index.js, 22, 12)) + diff --git a/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.types b/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.types new file mode 100644 index 0000000000000..2e7d031d5732f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsReusesExistingNodesMappingJSDocTypes.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** @type {?} */ +export const a = null; +>a : any +>null : null + +/** @type {*} */ +export const b = null; +>b : any +>null : null + +/** @type {string?} */ +export const c = null; +>c : string +>null : null + +/** @type {string=} */ +export const d = null; +>d : string +>null : null + +/** @type {string!} */ +export const e = null; +>e : string +>null : null + +/** @type {function(string, number): object} */ +export const f = null; +>f : (arg0: string, arg1: number) => any +>null : null + +/** @type {function(new: object, string, number)} */ +export const g = null; +>g : new (arg1: string, arg2: number) => any +>null : null + +/** @type {Object.} */ +export const h = null; +>h : { [x: string]: number; } +>null : null + diff --git a/tests/baselines/reference/jsDeclarationsTypeAliases.js b/tests/baselines/reference/jsDeclarationsTypeAliases.js new file mode 100644 index 0000000000000..0c6fe20d30b54 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeAliases.js @@ -0,0 +1,141 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeAliases.ts] //// + +//// [index.js] +export {}; // flag file as module +/** + * @typedef {string | number | symbol} PropName + */ + +/** + * Callback + * + * @callback NumberToStringCb + * @param {number} a + * @returns {string} + */ + +/** + * @template T + * @typedef {T & {name: string}} MixinName + */ + +/** + * Identity function + * + * @template T + * @callback Identity + * @param {T} x + * @returns {T} + */ + +//// [mixed.js] +/** + * @typedef {{x: string} | number | LocalThing | ExportedThing} SomeType + */ +/** + * @param {number} x + * @returns {SomeType} + */ +function doTheThing(x) { + return {x: ""+x}; +} +class ExportedThing { + z = "ok" +} +module.exports = { + doTheThing, + ExportedThing, +}; +class LocalThing { + y = "ok" +} + + +//// [index.js] +"use strict"; +exports.__esModule = true; +/** + * @typedef {string | number | symbol} PropName + */ +/** + * Callback + * + * @callback NumberToStringCb + * @param {number} a + * @returns {string} + */ +/** + * @template T + * @typedef {T & {name: string}} MixinName + */ +/** + * Identity function + * + * @template T + * @callback Identity + * @param {T} x + * @returns {T} + */ +//// [mixed.js] +/** + * @typedef {{x: string} | number | LocalThing | ExportedThing} SomeType + */ +/** + * @param {number} x + * @returns {SomeType} + */ +function doTheThing(x) { + return { x: "" + x }; +} +var ExportedThing = /** @class */ (function () { + function ExportedThing() { + this.z = "ok"; + } + return ExportedThing; +}()); +module.exports = { + doTheThing: doTheThing, + ExportedThing: ExportedThing +}; +var LocalThing = /** @class */ (function () { + function LocalThing() { + this.y = "ok"; + } + return LocalThing; +}()); + + +//// [index.d.ts] +export type PropName = string | number | symbol; +/** + * Callback + */ +export type NumberToStringCb = (a: number) => string; +export type MixinName = T & { + name: string; +}; +/** + * Identity function + */ +export type Identity = (x: T) => T; +//// [mixed.d.ts] +export type SomeType = number | { + x: string; +} | LocalThing | ExportedThing; +/** + * @typedef {{x: string} | number | LocalThing | ExportedThing} SomeType + */ +/** + * @param {number} x + * @returns {SomeType} + */ +export function doTheThing(x: number): number | { + x: string; +} | LocalThing | ExportedThing; +export class ExportedThing { + z: string; +} +declare class LocalThing { + y: string; +} +export {}; diff --git a/tests/baselines/reference/jsDeclarationsTypeAliases.symbols b/tests/baselines/reference/jsDeclarationsTypeAliases.symbols new file mode 100644 index 0000000000000..d8b045e86b609 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeAliases.symbols @@ -0,0 +1,69 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +export {}; // flag file as module +No type information for this code./** +No type information for this code. * @typedef {string | number | symbol} PropName +No type information for this code. */ +No type information for this code. +No type information for this code./** +No type information for this code. * Callback +No type information for this code. * +No type information for this code. * @callback NumberToStringCb +No type information for this code. * @param {number} a +No type information for this code. * @returns {string} +No type information for this code. */ +No type information for this code. +No type information for this code./** +No type information for this code. * @template T +No type information for this code. * @typedef {T & {name: string}} MixinName +No type information for this code. */ +No type information for this code. +No type information for this code./** +No type information for this code. * Identity function +No type information for this code. * +No type information for this code. * @template T +No type information for this code. * @callback Identity +No type information for this code. * @param {T} x +No type information for this code. * @returns {T} +No type information for this code. */ +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/mixed.js === +/** + * @typedef {{x: string} | number | LocalThing | ExportedThing} SomeType + */ +/** + * @param {number} x + * @returns {SomeType} + */ +function doTheThing(x) { +>doTheThing : Symbol(doTheThing, Decl(mixed.js, 0, 0)) +>x : Symbol(x, Decl(mixed.js, 7, 20)) + + return {x: ""+x}; +>x : Symbol(x, Decl(mixed.js, 8, 12)) +>x : Symbol(x, Decl(mixed.js, 7, 20)) +} +class ExportedThing { +>ExportedThing : Symbol(ExportedThing, Decl(mixed.js, 9, 1)) + + z = "ok" +>z : Symbol(ExportedThing.z, Decl(mixed.js, 10, 21)) +} +module.exports = { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/mixed", Decl(mixed.js, 0, 0)) +>module : Symbol(export=, Decl(mixed.js, 12, 1)) +>exports : Symbol(export=, Decl(mixed.js, 12, 1)) + + doTheThing, +>doTheThing : Symbol(doTheThing, Decl(mixed.js, 13, 18)) + + ExportedThing, +>ExportedThing : Symbol(ExportedThing, Decl(mixed.js, 14, 15)) + +}; +class LocalThing { +>LocalThing : Symbol(LocalThing, Decl(mixed.js, 16, 2)) + + y = "ok" +>y : Symbol(LocalThing.y, Decl(mixed.js, 17, 18)) +} + diff --git a/tests/baselines/reference/jsDeclarationsTypeAliases.types b/tests/baselines/reference/jsDeclarationsTypeAliases.types new file mode 100644 index 0000000000000..f2581249c251b --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeAliases.types @@ -0,0 +1,76 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +export {}; // flag file as module +No type information for this code./** +No type information for this code. * @typedef {string | number | symbol} PropName +No type information for this code. */ +No type information for this code. +No type information for this code./** +No type information for this code. * Callback +No type information for this code. * +No type information for this code. * @callback NumberToStringCb +No type information for this code. * @param {number} a +No type information for this code. * @returns {string} +No type information for this code. */ +No type information for this code. +No type information for this code./** +No type information for this code. * @template T +No type information for this code. * @typedef {T & {name: string}} MixinName +No type information for this code. */ +No type information for this code. +No type information for this code./** +No type information for this code. * Identity function +No type information for this code. * +No type information for this code. * @template T +No type information for this code. * @callback Identity +No type information for this code. * @param {T} x +No type information for this code. * @returns {T} +No type information for this code. */ +No type information for this code. +No type information for this code.=== tests/cases/conformance/jsdoc/declarations/mixed.js === +/** + * @typedef {{x: string} | number | LocalThing | ExportedThing} SomeType + */ +/** + * @param {number} x + * @returns {SomeType} + */ +function doTheThing(x) { +>doTheThing : (x: number) => number | { x: string; } | LocalThing | ExportedThing +>x : number + + return {x: ""+x}; +>{x: ""+x} : { x: string; } +>x : string +>""+x : string +>"" : "" +>x : number +} +class ExportedThing { +>ExportedThing : ExportedThing + + z = "ok" +>z : string +>"ok" : "ok" +} +module.exports = { +>module.exports = { doTheThing, ExportedThing,} : { doTheThing: (x: number) => number | { x: string; } | LocalThing | ExportedThing; ExportedThing: typeof ExportedThing; } +>module.exports : { doTheThing: (x: number) => number | { x: string; } | LocalThing | ExportedThing; ExportedThing: typeof ExportedThing; } +>module : { "tests/cases/conformance/jsdoc/declarations/mixed": { doTheThing: (x: number) => number | { x: string; } | LocalThing | ExportedThing; ExportedThing: typeof ExportedThing; }; } +>exports : { doTheThing: (x: number) => number | { x: string; } | LocalThing | ExportedThing; ExportedThing: typeof ExportedThing; } +>{ doTheThing, ExportedThing,} : { doTheThing: (x: number) => number | { x: string; } | LocalThing | ExportedThing; ExportedThing: typeof ExportedThing; } + + doTheThing, +>doTheThing : (x: number) => number | { x: string; } | LocalThing | ExportedThing + + ExportedThing, +>ExportedThing : typeof ExportedThing + +}; +class LocalThing { +>LocalThing : LocalThing + + y = "ok" +>y : string +>"ok" : "ok" +} + diff --git a/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.js b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.js new file mode 100644 index 0000000000000..d7c404f8bb56e --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.js @@ -0,0 +1,23 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReassignmentFromDeclaration.ts] //// + +//// [some-mod.d.ts] +interface Item { + x: string; +} +declare const items: Item[]; +export = items; +//// [index.js] +/** @type {typeof import("/some-mod")} */ +const items = []; +module.exports = items; + +//// [index.js] +/** @type {typeof import("/some-mod")} */ +var items = []; +module.exports = items; + + +//// [index.d.ts] +export = items; +/** @type {typeof import("/some-mod")} */ +declare const items: typeof import("/some-mod"); diff --git a/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.symbols b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.symbols new file mode 100644 index 0000000000000..96a988e2e113b --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.symbols @@ -0,0 +1,25 @@ +=== /some-mod.d.ts === +interface Item { +>Item : Symbol(Item, Decl(some-mod.d.ts, 0, 0)) + + x: string; +>x : Symbol(Item.x, Decl(some-mod.d.ts, 0, 16)) +} +declare const items: Item[]; +>items : Symbol(items, Decl(some-mod.d.ts, 3, 13)) +>Item : Symbol(Item, Decl(some-mod.d.ts, 0, 0)) + +export = items; +>items : Symbol(items, Decl(some-mod.d.ts, 3, 13)) + +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** @type {typeof import("/some-mod")} */ +const items = []; +>items : Symbol(items, Decl(index.js, 1, 5)) + +module.exports = items; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 1, 17)) +>exports : Symbol(export=, Decl(index.js, 1, 17)) +>items : Symbol(items, Decl(index.js, 1, 5)) + diff --git a/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.types b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.types new file mode 100644 index 0000000000000..ed020e5d4993e --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration.types @@ -0,0 +1,24 @@ +=== /some-mod.d.ts === +interface Item { + x: string; +>x : string +} +declare const items: Item[]; +>items : Item[] + +export = items; +>items : Item[] + +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** @type {typeof import("/some-mod")} */ +const items = []; +>items : Item[] +>[] : undefined[] + +module.exports = items; +>module.exports = items : { [n: number]: Item; length: number; toString(): string; toLocaleString(): string; pop(): Item; push(...items: Item[]): number; concat(...items: ConcatArray[]): Item[]; concat(...items: (Item | ConcatArray)[]): Item[]; join(separator?: string): string; reverse(): Item[]; shift(): Item; slice(start?: number, end?: number): Item[]; sort(compareFn?: (a: Item, b: Item) => number): Item[]; splice(start: number, deleteCount?: number): Item[]; splice(start: number, deleteCount: number, ...items: Item[]): Item[]; unshift(...items: Item[]): number; indexOf(searchElement: Item, fromIndex?: number): number; lastIndexOf(searchElement: Item, fromIndex?: number): number; every(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: Item, index: number, array: Item[]) => void, thisArg?: any): void; map(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): Item[]; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduce(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduceRight(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; find(predicate: (this: void, value: Item, index: number, obj: Item[]) => value is S, thisArg?: any): S; find(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): Item; findIndex(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): number; fill(value: Item, start?: number, end?: number): Item[]; copyWithin(target: number, start: number, end?: number): Item[]; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.unscopables](): { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; } +>module.exports : { [n: number]: Item; length: number; toString(): string; toLocaleString(): string; pop(): Item; push(...items: Item[]): number; concat(...items: ConcatArray[]): Item[]; concat(...items: (Item | ConcatArray)[]): Item[]; join(separator?: string): string; reverse(): Item[]; shift(): Item; slice(start?: number, end?: number): Item[]; sort(compareFn?: (a: Item, b: Item) => number): Item[]; splice(start: number, deleteCount?: number): Item[]; splice(start: number, deleteCount: number, ...items: Item[]): Item[]; unshift(...items: Item[]): number; indexOf(searchElement: Item, fromIndex?: number): number; lastIndexOf(searchElement: Item, fromIndex?: number): number; every(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: Item, index: number, array: Item[]) => void, thisArg?: any): void; map(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): Item[]; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduce(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduceRight(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; find(predicate: (this: void, value: Item, index: number, obj: Item[]) => value is S, thisArg?: any): S; find(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): Item; findIndex(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): number; fill(value: Item, start?: number, end?: number): Item[]; copyWithin(target: number, start: number, end?: number): Item[]; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.unscopables](): { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { [n: number]: Item; length: number; toString(): string; toLocaleString(): string; pop(): Item; push(...items: Item[]): number; concat(...items: ConcatArray[]): Item[]; concat(...items: (Item | ConcatArray)[]): Item[]; join(separator?: string): string; reverse(): Item[]; shift(): Item; slice(start?: number, end?: number): Item[]; sort(compareFn?: (a: Item, b: Item) => number): Item[]; splice(start: number, deleteCount?: number): Item[]; splice(start: number, deleteCount: number, ...items: Item[]): Item[]; unshift(...items: Item[]): number; indexOf(searchElement: Item, fromIndex?: number): number; lastIndexOf(searchElement: Item, fromIndex?: number): number; every(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: Item, index: number, array: Item[]) => void, thisArg?: any): void; map(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): Item[]; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduce(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduceRight(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; find(predicate: (this: void, value: Item, index: number, obj: Item[]) => value is S, thisArg?: any): S; find(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): Item; findIndex(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): number; fill(value: Item, start?: number, end?: number): Item[]; copyWithin(target: number, start: number, end?: number): Item[]; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.unscopables](): { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; }; } +>exports : { [n: number]: Item; length: number; toString(): string; toLocaleString(): string; pop(): Item; push(...items: Item[]): number; concat(...items: ConcatArray[]): Item[]; concat(...items: (Item | ConcatArray)[]): Item[]; join(separator?: string): string; reverse(): Item[]; shift(): Item; slice(start?: number, end?: number): Item[]; sort(compareFn?: (a: Item, b: Item) => number): Item[]; splice(start: number, deleteCount?: number): Item[]; splice(start: number, deleteCount: number, ...items: Item[]): Item[]; unshift(...items: Item[]): number; indexOf(searchElement: Item, fromIndex?: number): number; lastIndexOf(searchElement: Item, fromIndex?: number): number; every(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: Item, index: number, array: Item[]) => void, thisArg?: any): void; map(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): Item[]; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduce(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduceRight(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; find(predicate: (this: void, value: Item, index: number, obj: Item[]) => value is S, thisArg?: any): S; find(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): Item; findIndex(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): number; fill(value: Item, start?: number, end?: number): Item[]; copyWithin(target: number, start: number, end?: number): Item[]; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.unscopables](): { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; } +>items : Item[] + diff --git a/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.errors.txt b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.errors.txt new file mode 100644 index 0000000000000..b57edcd1c93fb --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/jsdoc/declarations/index.js(1,1): error TS9006: Declaration emit for this file requires using private name 'Item' from module '"tests/cases/conformance/jsdoc/declarations/some-mod"'. An explicit type annotation may unblock declaration emit. + + +==== tests/cases/conformance/jsdoc/declarations/index.js (1 errors) ==== + const items = require("./some-mod")(); + ~~~~~ +!!! error TS9006: Declaration emit for this file requires using private name 'Item' from module '"tests/cases/conformance/jsdoc/declarations/some-mod"'. An explicit type annotation may unblock declaration emit. + module.exports = items; +==== tests/cases/conformance/jsdoc/declarations/some-mod.d.ts (0 errors) ==== + interface Item { + x: string; + } + declare function getItems(): Item[]; + export = getItems; \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.js b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.js new file mode 100644 index 0000000000000..02068c5cef713 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.js @@ -0,0 +1,15 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReassignmentFromDeclaration2.ts] //// + +//// [some-mod.d.ts] +interface Item { + x: string; +} +declare function getItems(): Item[]; +export = getItems; +//// [index.js] +const items = require("./some-mod")(); +module.exports = items; + +//// [index.js] +var items = require("./some-mod")(); +module.exports = items; diff --git a/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.symbols b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.symbols new file mode 100644 index 0000000000000..283b16b647a8d --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.symbols @@ -0,0 +1,26 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const items = require("./some-mod")(); +>items : Symbol(items, Decl(index.js, 0, 5)) +>require : Symbol(require) +>"./some-mod" : Symbol("tests/cases/conformance/jsdoc/declarations/some-mod", Decl(some-mod.d.ts, 0, 0)) + +module.exports = items; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 0, 38)) +>exports : Symbol(export=, Decl(index.js, 0, 38)) +>items : Symbol(items, Decl(index.js, 0, 5)) + +=== tests/cases/conformance/jsdoc/declarations/some-mod.d.ts === +interface Item { +>Item : Symbol(Item, Decl(some-mod.d.ts, 0, 0)) + + x: string; +>x : Symbol(Item.x, Decl(some-mod.d.ts, 0, 16)) +} +declare function getItems(): Item[]; +>getItems : Symbol(getItems, Decl(some-mod.d.ts, 2, 1)) +>Item : Symbol(Item, Decl(some-mod.d.ts, 0, 0)) + +export = getItems; +>getItems : Symbol(getItems, Decl(some-mod.d.ts, 2, 1)) + diff --git a/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.types b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.types new file mode 100644 index 0000000000000..db7d35757d18f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReassignmentFromDeclaration2.types @@ -0,0 +1,26 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const items = require("./some-mod")(); +>items : Item[] +>require("./some-mod")() : Item[] +>require("./some-mod") : () => Item[] +>require : any +>"./some-mod" : "./some-mod" + +module.exports = items; +>module.exports = items : { [n: number]: Item; length: number; toString(): string; toLocaleString(): string; pop(): Item; push(...items: Item[]): number; concat(...items: ConcatArray[]): Item[]; concat(...items: (Item | ConcatArray)[]): Item[]; join(separator?: string): string; reverse(): Item[]; shift(): Item; slice(start?: number, end?: number): Item[]; sort(compareFn?: (a: Item, b: Item) => number): Item[]; splice(start: number, deleteCount?: number): Item[]; splice(start: number, deleteCount: number, ...items: Item[]): Item[]; unshift(...items: Item[]): number; indexOf(searchElement: Item, fromIndex?: number): number; lastIndexOf(searchElement: Item, fromIndex?: number): number; every(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: Item, index: number, array: Item[]) => void, thisArg?: any): void; map(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): Item[]; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduce(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduceRight(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; find(predicate: (this: void, value: Item, index: number, obj: Item[]) => value is S, thisArg?: any): S; find(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): Item; findIndex(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): number; fill(value: Item, start?: number, end?: number): Item[]; copyWithin(target: number, start: number, end?: number): Item[]; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.unscopables](): { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; } +>module.exports : { [n: number]: Item; length: number; toString(): string; toLocaleString(): string; pop(): Item; push(...items: Item[]): number; concat(...items: ConcatArray[]): Item[]; concat(...items: (Item | ConcatArray)[]): Item[]; join(separator?: string): string; reverse(): Item[]; shift(): Item; slice(start?: number, end?: number): Item[]; sort(compareFn?: (a: Item, b: Item) => number): Item[]; splice(start: number, deleteCount?: number): Item[]; splice(start: number, deleteCount: number, ...items: Item[]): Item[]; unshift(...items: Item[]): number; indexOf(searchElement: Item, fromIndex?: number): number; lastIndexOf(searchElement: Item, fromIndex?: number): number; every(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: Item, index: number, array: Item[]) => void, thisArg?: any): void; map(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): Item[]; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduce(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduceRight(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; find(predicate: (this: void, value: Item, index: number, obj: Item[]) => value is S, thisArg?: any): S; find(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): Item; findIndex(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): number; fill(value: Item, start?: number, end?: number): Item[]; copyWithin(target: number, start: number, end?: number): Item[]; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.unscopables](): { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { [n: number]: Item; length: number; toString(): string; toLocaleString(): string; pop(): Item; push(...items: Item[]): number; concat(...items: ConcatArray[]): Item[]; concat(...items: (Item | ConcatArray)[]): Item[]; join(separator?: string): string; reverse(): Item[]; shift(): Item; slice(start?: number, end?: number): Item[]; sort(compareFn?: (a: Item, b: Item) => number): Item[]; splice(start: number, deleteCount?: number): Item[]; splice(start: number, deleteCount: number, ...items: Item[]): Item[]; unshift(...items: Item[]): number; indexOf(searchElement: Item, fromIndex?: number): number; lastIndexOf(searchElement: Item, fromIndex?: number): number; every(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: Item, index: number, array: Item[]) => void, thisArg?: any): void; map(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): Item[]; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduce(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduceRight(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; find(predicate: (this: void, value: Item, index: number, obj: Item[]) => value is S, thisArg?: any): S; find(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): Item; findIndex(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): number; fill(value: Item, start?: number, end?: number): Item[]; copyWithin(target: number, start: number, end?: number): Item[]; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.unscopables](): { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; }; } +>exports : { [n: number]: Item; length: number; toString(): string; toLocaleString(): string; pop(): Item; push(...items: Item[]): number; concat(...items: ConcatArray[]): Item[]; concat(...items: (Item | ConcatArray)[]): Item[]; join(separator?: string): string; reverse(): Item[]; shift(): Item; slice(start?: number, end?: number): Item[]; sort(compareFn?: (a: Item, b: Item) => number): Item[]; splice(start: number, deleteCount?: number): Item[]; splice(start: number, deleteCount: number, ...items: Item[]): Item[]; unshift(...items: Item[]): number; indexOf(searchElement: Item, fromIndex?: number): number; lastIndexOf(searchElement: Item, fromIndex?: number): number; every(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; some(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): boolean; forEach(callbackfn: (value: Item, index: number, array: Item[]) => void, thisArg?: any): void; map(callbackfn: (value: Item, index: number, array: Item[]) => U, thisArg?: any): U[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: Item, index: number, array: Item[]) => unknown, thisArg?: any): Item[]; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduce(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduce(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item): Item; reduceRight(callbackfn: (previousValue: Item, currentValue: Item, currentIndex: number, array: Item[]) => Item, initialValue: Item): Item; reduceRight(callbackfn: (previousValue: U, currentValue: Item, currentIndex: number, array: Item[]) => U, initialValue: U): U; find(predicate: (this: void, value: Item, index: number, obj: Item[]) => value is S, thisArg?: any): S; find(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): Item; findIndex(predicate: (value: Item, index: number, obj: Item[]) => unknown, thisArg?: any): number; fill(value: Item, start?: number, end?: number): Item[]; copyWithin(target: number, start: number, end?: number): Item[]; [Symbol.iterator](): IterableIterator; entries(): IterableIterator<[number, Item]>; keys(): IterableIterator; values(): IterableIterator; [Symbol.unscopables](): { copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: boolean; values: boolean; }; } +>items : Item[] + +=== tests/cases/conformance/jsdoc/declarations/some-mod.d.ts === +interface Item { + x: string; +>x : string +} +declare function getItems(): Item[]; +>getItems : () => Item[] + +export = getItems; +>getItems : () => Item[] + diff --git a/tests/baselines/reference/jsDeclarationsTypeReferences.js b/tests/baselines/reference/jsDeclarationsTypeReferences.js new file mode 100644 index 0000000000000..9e6a95d32e190 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReferences.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReferences.ts] //// + +//// [index.d.ts] +declare module "fs" { + export class Something {} +} +//// [index.js] +/// + +const Something = require("fs").Something; + +const thing = new Something(); + +module.exports = { + thing +}; + +//// [index.js] +/// +var Something = require("fs").Something; +var thing = new Something(); +module.exports = { + thing: thing +}; + + +//// [index.d.ts] +/// +export const thing: import("fs").Something; diff --git a/tests/baselines/reference/jsDeclarationsTypeReferences.symbols b/tests/baselines/reference/jsDeclarationsTypeReferences.symbols new file mode 100644 index 0000000000000..258b4d224a807 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReferences.symbols @@ -0,0 +1,30 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +/// + +const Something = require("fs").Something; +>Something : Symbol(Something, Decl(index.js, 2, 5)) +>require("fs").Something : Symbol(Something, Decl(index.d.ts, 0, 21)) +>require : Symbol(require) +>"fs" : Symbol("fs", Decl(index.d.ts, 0, 0)) +>Something : Symbol(Something, Decl(index.d.ts, 0, 21)) + +const thing = new Something(); +>thing : Symbol(thing, Decl(index.js, 4, 5)) +>Something : Symbol(Something, Decl(index.js, 2, 5)) + +module.exports = { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 4, 30)) +>exports : Symbol(export=, Decl(index.js, 4, 30)) + + thing +>thing : Symbol(thing, Decl(index.js, 6, 18)) + +}; +=== tests/cases/conformance/jsdoc/declarations/node_modules/@types/node/index.d.ts === +declare module "fs" { +>"fs" : Symbol("fs", Decl(index.d.ts, 0, 0)) + + export class Something {} +>Something : Symbol(Something, Decl(index.d.ts, 0, 21)) +} diff --git a/tests/baselines/reference/jsDeclarationsTypeReferences.types b/tests/baselines/reference/jsDeclarationsTypeReferences.types new file mode 100644 index 0000000000000..15545aff3a33c --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypeReferences.types @@ -0,0 +1,34 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +/// + +const Something = require("fs").Something; +>Something : typeof import("fs").Something +>require("fs").Something : typeof import("fs").Something +>require("fs") : typeof import("fs") +>require : any +>"fs" : "fs" +>Something : typeof import("fs").Something + +const thing = new Something(); +>thing : import("fs").Something +>new Something() : import("fs").Something +>Something : typeof import("fs").Something + +module.exports = { +>module.exports = { thing} : { thing: import("fs").Something; } +>module.exports : { thing: import("fs").Something; } +>module : { "tests/cases/conformance/jsdoc/declarations/index": { thing: import("fs").Something; }; } +>exports : { thing: import("fs").Something; } +>{ thing} : { thing: import("fs").Something; } + + thing +>thing : import("fs").Something + +}; +=== tests/cases/conformance/jsdoc/declarations/node_modules/@types/node/index.d.ts === +declare module "fs" { +>"fs" : typeof import("fs") + + export class Something {} +>Something : Something +} diff --git a/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.js b/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.js new file mode 100644 index 0000000000000..f8ff0175d9502 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.js @@ -0,0 +1,95 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefAndImportTypes.ts] //// + +//// [conn.js] +/** + * @typedef {string | number} Whatever + */ + +class Conn { + constructor() {} + item = 3; + method() {} +} + +module.exports = Conn; + +//// [usage.js] +/** + * @typedef {import("./conn")} Conn + */ + +class Wrap { + /** + * @param {Conn} c + */ + constructor(c) { + this.connItem = c.item; + /** @type {import("./conn").Whatever} */ + this.another = ""; + } +} + +module.exports = { + Wrap +}; + + +//// [conn.js] +/** + * @typedef {string | number} Whatever + */ +var Conn = /** @class */ (function () { + function Conn() { + this.item = 3; + } + Conn.prototype.method = function () { }; + return Conn; +}()); +module.exports = Conn; +//// [usage.js] +/** + * @typedef {import("./conn")} Conn + */ +var Wrap = /** @class */ (function () { + /** + * @param {Conn} c + */ + function Wrap(c) { + this.connItem = c.item; + /** @type {import("./conn").Whatever} */ + this.another = ""; + } + return Wrap; +}()); +module.exports = { + Wrap: Wrap +}; + + +//// [conn.d.ts] +export = Conn; +/** + * @typedef {string | number} Whatever + */ +declare class Conn { + item: number; + method(): void; +} +declare namespace Conn { + export { Whatever }; +} +type Whatever = string | number; +//// [usage.d.ts] +export type Conn = import("./conn"); +/** + * @typedef {import("./conn")} Conn + */ +export class Wrap { + /** + * @param {Conn} c + */ + constructor(c: import("./conn")); + connItem: number; + /** @type {import("./conn").Whatever} */ + another: import("./conn").Whatever; +} diff --git a/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.symbols b/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.symbols new file mode 100644 index 0000000000000..460982b6b97da --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.symbols @@ -0,0 +1,62 @@ +=== tests/cases/conformance/jsdoc/declarations/conn.js === +/** + * @typedef {string | number} Whatever + */ + +class Conn { +>Conn : Symbol(Conn, Decl(conn.js, 0, 0)) + + constructor() {} + item = 3; +>item : Symbol(Conn.item, Decl(conn.js, 5, 20)) + + method() {} +>method : Symbol(Conn.method, Decl(conn.js, 6, 13)) +} + +module.exports = Conn; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/conn", Decl(conn.js, 0, 0)) +>module : Symbol(export=, Decl(conn.js, 8, 1)) +>exports : Symbol(export=, Decl(conn.js, 8, 1)) +>Conn : Symbol(Conn, Decl(conn.js, 0, 0)) + +=== tests/cases/conformance/jsdoc/declarations/usage.js === +/** + * @typedef {import("./conn")} Conn + */ + +class Wrap { +>Wrap : Symbol(Wrap, Decl(usage.js, 0, 0)) + + /** + * @param {Conn} c + */ + constructor(c) { +>c : Symbol(c, Decl(usage.js, 8, 16)) + + this.connItem = c.item; +>this.connItem : Symbol(Wrap.connItem, Decl(usage.js, 8, 20)) +>this : Symbol(Wrap, Decl(usage.js, 0, 0)) +>connItem : Symbol(Wrap.connItem, Decl(usage.js, 8, 20)) +>c.item : Symbol(Conn.item, Decl(conn.js, 5, 20)) +>c : Symbol(c, Decl(usage.js, 8, 16)) +>item : Symbol(Conn.item, Decl(conn.js, 5, 20)) + + /** @type {import("./conn").Whatever} */ + this.another = ""; +>this.another : Symbol(Wrap.another, Decl(usage.js, 9, 31)) +>this : Symbol(Wrap, Decl(usage.js, 0, 0)) +>another : Symbol(Wrap.another, Decl(usage.js, 9, 31)) + } +} + +module.exports = { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/usage", Decl(usage.js, 0, 0)) +>module : Symbol(export=, Decl(usage.js, 13, 1)) +>exports : Symbol(export=, Decl(usage.js, 13, 1)) + + Wrap +>Wrap : Symbol(Wrap, Decl(usage.js, 15, 18)) + +}; + diff --git a/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.types b/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.types new file mode 100644 index 0000000000000..de61eae51f98d --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefAndImportTypes.types @@ -0,0 +1,69 @@ +=== tests/cases/conformance/jsdoc/declarations/conn.js === +/** + * @typedef {string | number} Whatever + */ + +class Conn { +>Conn : Conn + + constructor() {} + item = 3; +>item : number +>3 : 3 + + method() {} +>method : () => void +} + +module.exports = Conn; +>module.exports = Conn : typeof Conn +>module.exports : typeof Conn +>module : { "tests/cases/conformance/jsdoc/declarations/conn": typeof Conn; } +>exports : typeof Conn +>Conn : typeof Conn + +=== tests/cases/conformance/jsdoc/declarations/usage.js === +/** + * @typedef {import("./conn")} Conn + */ + +class Wrap { +>Wrap : Wrap + + /** + * @param {Conn} c + */ + constructor(c) { +>c : import("tests/cases/conformance/jsdoc/declarations/conn") + + this.connItem = c.item; +>this.connItem = c.item : number +>this.connItem : number +>this : this +>connItem : number +>c.item : number +>c : import("tests/cases/conformance/jsdoc/declarations/conn") +>item : number + + /** @type {import("./conn").Whatever} */ + this.another = ""; +>this.another = "" : "" +>this.another : string | number +>this : this +>another : string | number +>"" : "" + } +} + +module.exports = { +>module.exports = { Wrap} : { Wrap: typeof Wrap; } +>module.exports : { Wrap: typeof Wrap; } +>module : { "tests/cases/conformance/jsdoc/declarations/usage": { Wrap: typeof Wrap; }; } +>exports : { Wrap: typeof Wrap; } +>{ Wrap} : { Wrap: typeof Wrap; } + + Wrap +>Wrap : typeof Wrap + +}; + diff --git a/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.js b/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.js new file mode 100644 index 0000000000000..e30e18fd151e9 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.js @@ -0,0 +1,64 @@ +//// [index.js] +/** + * Options for Foo <------------ + * @typedef {Object} FooOptions + * @property {boolean} bar - Marvin K Mooney + * @property {string} baz - Sylvester McMonkey McBean + */ + +/** + * Multiline + * Options + * for Foo <------------ + * @typedef {Object} BarOptions + * @property {boolean} bar - Marvin K Mooney + * @property {string} baz - Sylvester McMonkey McBean + */ + + +//// [index.js] +/** + * Options for Foo <------------ + * @typedef {Object} FooOptions + * @property {boolean} bar - Marvin K Mooney + * @property {string} baz - Sylvester McMonkey McBean + */ +/** + * Multiline + * Options + * for Foo <------------ + * @typedef {Object} BarOptions + * @property {boolean} bar - Marvin K Mooney + * @property {string} baz - Sylvester McMonkey McBean + */ + + +//// [index.d.ts] +/** + * Options for Foo <------------ + */ +type FooOptions = { + /** + * - Marvin K Mooney + */ + bar: boolean; + /** + * - Sylvester McMonkey McBean + */ + baz: string; +}; +/** + * Multiline + * Options + * for Foo <------------ + */ +type BarOptions = { + /** + * - Marvin K Mooney + */ + bar: boolean; + /** + * - Sylvester McMonkey McBean + */ + baz: string; +}; diff --git a/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.symbols b/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.symbols new file mode 100644 index 0000000000000..da2182e01c45f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.symbols @@ -0,0 +1,18 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** +No type information for this code. * Options for Foo <------------ +No type information for this code. * @typedef {Object} FooOptions +No type information for this code. * @property {boolean} bar - Marvin K Mooney +No type information for this code. * @property {string} baz - Sylvester McMonkey McBean +No type information for this code. */ +No type information for this code. +No type information for this code./** +No type information for this code. * Multiline +No type information for this code. * Options +No type information for this code. * for Foo <------------ +No type information for this code. * @typedef {Object} BarOptions +No type information for this code. * @property {boolean} bar - Marvin K Mooney +No type information for this code. * @property {string} baz - Sylvester McMonkey McBean +No type information for this code. */ +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.types b/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.types new file mode 100644 index 0000000000000..da2182e01c45f --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefDescriptionsPreserved.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +/** +No type information for this code. * Options for Foo <------------ +No type information for this code. * @typedef {Object} FooOptions +No type information for this code. * @property {boolean} bar - Marvin K Mooney +No type information for this code. * @property {string} baz - Sylvester McMonkey McBean +No type information for this code. */ +No type information for this code. +No type information for this code./** +No type information for this code. * Multiline +No type information for this code. * Options +No type information for this code. * for Foo <------------ +No type information for this code. * @typedef {Object} BarOptions +No type information for this code. * @property {boolean} bar - Marvin K Mooney +No type information for this code. * @property {string} baz - Sylvester McMonkey McBean +No type information for this code. */ +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.js b/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.js new file mode 100644 index 0000000000000..590ef5633bba3 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.js @@ -0,0 +1,165 @@ +//// [tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefPropertyAndExportAssignment.ts] //// + +//// [module.js] +/** @typedef {'parseHTML'|'styleLayout'} TaskGroupIds */ + +/** + * @typedef TaskGroup + * @property {TaskGroupIds} id + * @property {string} label + * @property {string[]} traceEventNames + */ + +/** + * @type {{[P in TaskGroupIds]: {id: P, label: string}}} + */ +const taskGroups = { + parseHTML: { + id: 'parseHTML', + label: 'Parse HTML & CSS' + }, + styleLayout: { + id: 'styleLayout', + label: 'Style & Layout' + }, +} + +/** @type {Object} */ +const taskNameToGroup = {}; + +module.exports = { + taskGroups, + taskNameToGroup, +}; +//// [index.js] +const {taskGroups, taskNameToGroup} = require('./module.js'); + +/** @typedef {import('./module.js').TaskGroup} TaskGroup */ + +/** + * @typedef TaskNode + * @prop {TaskNode[]} children + * @prop {TaskNode|undefined} parent + * @prop {TaskGroup} group + */ + +/** @typedef {{timers: Map}} PriorTaskData */ +class MainThreadTasks { + /** + * @param {TaskGroup} x + * @param {TaskNode} y + */ + constructor(x, y){} +} + +module.exports = MainThreadTasks; + +//// [module.js] +/** @typedef {'parseHTML'|'styleLayout'} TaskGroupIds */ +/** + * @typedef TaskGroup + * @property {TaskGroupIds} id + * @property {string} label + * @property {string[]} traceEventNames + */ +/** + * @type {{[P in TaskGroupIds]: {id: P, label: string}}} + */ +var taskGroups = { + parseHTML: { + id: 'parseHTML', + label: 'Parse HTML & CSS' + }, + styleLayout: { + id: 'styleLayout', + label: 'Style & Layout' + } +}; +/** @type {Object} */ +var taskNameToGroup = {}; +module.exports = { + taskGroups: taskGroups, + taskNameToGroup: taskNameToGroup +}; +//// [index.js] +var _a = require('./module.js'), taskGroups = _a.taskGroups, taskNameToGroup = _a.taskNameToGroup; +/** @typedef {import('./module.js').TaskGroup} TaskGroup */ +/** + * @typedef TaskNode + * @prop {TaskNode[]} children + * @prop {TaskNode|undefined} parent + * @prop {TaskGroup} group + */ +/** @typedef {{timers: Map}} PriorTaskData */ +var MainThreadTasks = /** @class */ (function () { + /** + * @param {TaskGroup} x + * @param {TaskNode} y + */ + function MainThreadTasks(x, y) { + } + return MainThreadTasks; +}()); +module.exports = MainThreadTasks; + + +//// [module.d.ts] +export type TaskGroupIds = "parseHTML" | "styleLayout"; +export type TaskGroup = { + id: "parseHTML" | "styleLayout"; + label: string; + traceEventNames: string[]; +}; +/** @typedef {'parseHTML'|'styleLayout'} TaskGroupIds */ +/** + * @typedef TaskGroup + * @property {TaskGroupIds} id + * @property {string} label + * @property {string[]} traceEventNames + */ +/** + * @type {{[P in TaskGroupIds]: {id: P, label: string}}} + */ +export const taskGroups: { + [P in TaskGroupIds]: { + id: P; + label: string; + }; +}; +/** @type {Object} */ +export const taskNameToGroup: { + [x: string]: TaskGroup; +}; +//// [index.d.ts] +export = MainThreadTasks; +/** @typedef {import('./module.js').TaskGroup} TaskGroup */ +/** + * @typedef TaskNode + * @prop {TaskNode[]} children + * @prop {TaskNode|undefined} parent + * @prop {TaskGroup} group + */ +/** @typedef {{timers: Map}} PriorTaskData */ +declare class MainThreadTasks { + /** + * @param {TaskGroup} x + * @param {TaskNode} y + */ + constructor(x: import("./module.js").TaskGroup, y: TaskNode); +} +declare namespace MainThreadTasks { + export { TaskGroup, TaskNode, PriorTaskData }; +} +type TaskNode = { + children: TaskNode[]; + parent: TaskNode; + group: import("./module.js").TaskGroup; +}; +type TaskGroup = { + id: "parseHTML" | "styleLayout"; + label: string; + traceEventNames: string[]; +}; +type PriorTaskData = { + timers: Map; +}; diff --git a/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.symbols b/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.symbols new file mode 100644 index 0000000000000..ebe674cf51aa9 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.symbols @@ -0,0 +1,89 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const {taskGroups, taskNameToGroup} = require('./module.js'); +>taskGroups : Symbol(taskGroups, Decl(index.js, 0, 7)) +>taskNameToGroup : Symbol(taskNameToGroup, Decl(index.js, 0, 18)) +>require : Symbol(require) +>'./module.js' : Symbol("tests/cases/conformance/jsdoc/declarations/module", Decl(module.js, 0, 0)) + +/** @typedef {import('./module.js').TaskGroup} TaskGroup */ + +/** + * @typedef TaskNode + * @prop {TaskNode[]} children + * @prop {TaskNode|undefined} parent + * @prop {TaskGroup} group + */ + +/** @typedef {{timers: Map}} PriorTaskData */ +class MainThreadTasks { +>MainThreadTasks : Symbol(MainThreadTasks, Decl(index.js, 0, 61)) + + /** + * @param {TaskGroup} x + * @param {TaskNode} y + */ + constructor(x, y){} +>x : Symbol(x, Decl(index.js, 17, 16)) +>y : Symbol(y, Decl(index.js, 17, 18)) +} + +module.exports = MainThreadTasks; +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/index", Decl(index.js, 0, 0)) +>module : Symbol(export=, Decl(index.js, 18, 1)) +>exports : Symbol(export=, Decl(index.js, 18, 1)) +>MainThreadTasks : Symbol(MainThreadTasks, Decl(index.js, 0, 61)) + +=== tests/cases/conformance/jsdoc/declarations/module.js === +/** @typedef {'parseHTML'|'styleLayout'} TaskGroupIds */ + +/** + * @typedef TaskGroup + * @property {TaskGroupIds} id + * @property {string} label + * @property {string[]} traceEventNames + */ + +/** + * @type {{[P in TaskGroupIds]: {id: P, label: string}}} + */ +const taskGroups = { +>taskGroups : Symbol(taskGroups, Decl(module.js, 12, 5)) + + parseHTML: { +>parseHTML : Symbol(parseHTML, Decl(module.js, 12, 20)) + + id: 'parseHTML', +>id : Symbol(id, Decl(module.js, 13, 16)) + + label: 'Parse HTML & CSS' +>label : Symbol(label, Decl(module.js, 14, 24)) + + }, + styleLayout: { +>styleLayout : Symbol(styleLayout, Decl(module.js, 16, 6)) + + id: 'styleLayout', +>id : Symbol(id, Decl(module.js, 17, 18)) + + label: 'Style & Layout' +>label : Symbol(label, Decl(module.js, 18, 26)) + + }, +} + +/** @type {Object} */ +const taskNameToGroup = {}; +>taskNameToGroup : Symbol(taskNameToGroup, Decl(module.js, 24, 5)) + +module.exports = { +>module.exports : Symbol("tests/cases/conformance/jsdoc/declarations/module", Decl(module.js, 0, 0)) +>module : Symbol(export=, Decl(module.js, 24, 27)) +>exports : Symbol(export=, Decl(module.js, 24, 27)) + + taskGroups, +>taskGroups : Symbol(taskGroups, Decl(module.js, 26, 18)) + + taskNameToGroup, +>taskNameToGroup : Symbol(taskNameToGroup, Decl(module.js, 27, 15)) + +}; diff --git a/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.types b/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.types new file mode 100644 index 0000000000000..54433c6d45f17 --- /dev/null +++ b/tests/baselines/reference/jsDeclarationsTypedefPropertyAndExportAssignment.types @@ -0,0 +1,101 @@ +=== tests/cases/conformance/jsdoc/declarations/index.js === +const {taskGroups, taskNameToGroup} = require('./module.js'); +>taskGroups : { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; } +>taskNameToGroup : { [x: string]: import("tests/cases/conformance/jsdoc/declarations/module").TaskGroup; } +>require('./module.js') : { taskGroups: { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; }; taskNameToGroup: { [x: string]: import("tests/cases/conformance/jsdoc/declarations/module").TaskGroup; }; } +>require : any +>'./module.js' : "./module.js" + +/** @typedef {import('./module.js').TaskGroup} TaskGroup */ + +/** + * @typedef TaskNode + * @prop {TaskNode[]} children + * @prop {TaskNode|undefined} parent + * @prop {TaskGroup} group + */ + +/** @typedef {{timers: Map}} PriorTaskData */ +class MainThreadTasks { +>MainThreadTasks : MainThreadTasks + + /** + * @param {TaskGroup} x + * @param {TaskNode} y + */ + constructor(x, y){} +>x : import("tests/cases/conformance/jsdoc/declarations/module").TaskGroup +>y : TaskNode +} + +module.exports = MainThreadTasks; +>module.exports = MainThreadTasks : typeof MainThreadTasks +>module.exports : typeof MainThreadTasks +>module : { "tests/cases/conformance/jsdoc/declarations/index": typeof MainThreadTasks; } +>exports : typeof MainThreadTasks +>MainThreadTasks : typeof MainThreadTasks + +=== tests/cases/conformance/jsdoc/declarations/module.js === +/** @typedef {'parseHTML'|'styleLayout'} TaskGroupIds */ + +/** + * @typedef TaskGroup + * @property {TaskGroupIds} id + * @property {string} label + * @property {string[]} traceEventNames + */ + +/** + * @type {{[P in TaskGroupIds]: {id: P, label: string}}} + */ +const taskGroups = { +>taskGroups : { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; } +>{ parseHTML: { id: 'parseHTML', label: 'Parse HTML & CSS' }, styleLayout: { id: 'styleLayout', label: 'Style & Layout' },} : { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; } + + parseHTML: { +>parseHTML : { id: "parseHTML"; label: string; } +>{ id: 'parseHTML', label: 'Parse HTML & CSS' } : { id: "parseHTML"; label: string; } + + id: 'parseHTML', +>id : "parseHTML" +>'parseHTML' : "parseHTML" + + label: 'Parse HTML & CSS' +>label : string +>'Parse HTML & CSS' : "Parse HTML & CSS" + + }, + styleLayout: { +>styleLayout : { id: "styleLayout"; label: string; } +>{ id: 'styleLayout', label: 'Style & Layout' } : { id: "styleLayout"; label: string; } + + id: 'styleLayout', +>id : "styleLayout" +>'styleLayout' : "styleLayout" + + label: 'Style & Layout' +>label : string +>'Style & Layout' : "Style & Layout" + + }, +} + +/** @type {Object} */ +const taskNameToGroup = {}; +>taskNameToGroup : { [x: string]: TaskGroup; } +>{} : {} + +module.exports = { +>module.exports = { taskGroups, taskNameToGroup,} : { taskGroups: { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; }; taskNameToGroup: { [x: string]: TaskGroup; }; } +>module.exports : { taskGroups: { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; }; taskNameToGroup: { [x: string]: TaskGroup; }; } +>module : { "tests/cases/conformance/jsdoc/declarations/module": { taskGroups: { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; }; taskNameToGroup: { [x: string]: TaskGroup; }; }; } +>exports : { taskGroups: { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; }; taskNameToGroup: { [x: string]: TaskGroup; }; } +>{ taskGroups, taskNameToGroup,} : { taskGroups: { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; }; taskNameToGroup: { [x: string]: TaskGroup; }; } + + taskGroups, +>taskGroups : { parseHTML: { id: "parseHTML"; label: string; }; styleLayout: { id: "styleLayout"; label: string; }; } + + taskNameToGroup, +>taskNameToGroup : { [x: string]: TaskGroup; } + +}; diff --git a/tests/baselines/reference/jsEnumCrossFileExport.symbols b/tests/baselines/reference/jsEnumCrossFileExport.symbols index 0ddc0d5b55128..10bf9c60045ed 100644 --- a/tests/baselines/reference/jsEnumCrossFileExport.symbols +++ b/tests/baselines/reference/jsEnumCrossFileExport.symbols @@ -67,11 +67,13 @@ Other.Cls = class { >this.method : Symbol(Cls.method, Decl(index.js, 1, 19)) >this : Symbol(Cls, Decl(index.js, 1, 11)) >method : Symbol(Cls.method, Decl(index.js, 1, 19)) +>Host.UserMetrics.Action.WindowDocked : Symbol(WindowDocked, Decl(enumDef.js, 3, 27)) >Host.UserMetrics.Action : Symbol(Host.UserMetrics.Action, Decl(enumDef.js, 1, 22), Decl(enumDef.js, 3, 17), Decl(enumDef.js, 2, 4)) >Host.UserMetrics : Symbol(Host.UserMetrics, Decl(enumDef.js, 0, 14), Decl(enumDef.js, 3, 5), Decl(enumDef.js, 15, 5), Decl(enumDef.js, 10, 26)) >Host : Symbol(Host, Decl(enumDef.js, 0, 3), Decl(enumDef.js, 0, 14), Decl(enumDef.js, 1, 22), Decl(enumDef.js, 8, 2), Decl(enumDef.js, 10, 21)) >UserMetrics : Symbol(Host.UserMetrics, Decl(enumDef.js, 0, 14), Decl(enumDef.js, 3, 5), Decl(enumDef.js, 15, 5), Decl(enumDef.js, 10, 26)) >Action : Symbol(Host.UserMetrics.Action, Decl(enumDef.js, 1, 22), Decl(enumDef.js, 3, 17), Decl(enumDef.js, 2, 4)) +>WindowDocked : Symbol(WindowDocked, Decl(enumDef.js, 3, 27)) } } diff --git a/tests/baselines/reference/jsEnumCrossFileExport.types b/tests/baselines/reference/jsEnumCrossFileExport.types index 24acb348ada67..4477b71a99987 100644 --- a/tests/baselines/reference/jsEnumCrossFileExport.types +++ b/tests/baselines/reference/jsEnumCrossFileExport.types @@ -13,11 +13,11 @@ Host.UserMetrics = {}; /** @enum {number} */ Host.UserMetrics.Action = { >Host.UserMetrics.Action = { WindowDocked: 1, WindowUndocked: 2, ScriptsBreakpointSet: 3, TimelineStarted: 4,} : { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; } ->Host.UserMetrics.Action : error +>Host.UserMetrics.Action : { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; } >Host.UserMetrics : typeof Host.UserMetrics >Host : typeof Host >UserMetrics : typeof Host.UserMetrics ->Action : any +>Action : { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; } >{ WindowDocked: 1, WindowUndocked: 2, ScriptsBreakpointSet: 3, TimelineStarted: 4,} : { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; } WindowDocked: 1, @@ -45,11 +45,11 @@ Host.UserMetrics.Action = { */ Host.UserMetrics.Blah = { >Host.UserMetrics.Blah = { x: 12} : { x: number; } ->Host.UserMetrics.Blah : error +>Host.UserMetrics.Blah : { x: number; } >Host.UserMetrics : typeof Host.UserMetrics >Host : typeof Host >UserMetrics : typeof Host.UserMetrics ->Blah : any +>Blah : { x: number; } >{ x: 12} : { x: number; } x: 12 @@ -83,13 +83,13 @@ Other.Cls = class { >this.method : (p: number) => void >this : this >method : (p: number) => void ->Host.UserMetrics.Action.WindowDocked : error ->Host.UserMetrics.Action : any +>Host.UserMetrics.Action.WindowDocked : number +>Host.UserMetrics.Action : { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; } >Host.UserMetrics : typeof Host.UserMetrics >Host : typeof Host >UserMetrics : typeof Host.UserMetrics ->Action : any ->WindowDocked : any +>Action : { WindowDocked: number; WindowUndocked: number; ScriptsBreakpointSet: number; TimelineStarted: number; } +>WindowDocked : number } } diff --git a/tests/baselines/reference/jsEnumTagOnObjectFrozen.symbols b/tests/baselines/reference/jsEnumTagOnObjectFrozen.symbols index 32a9543fbf768..18610423aeaff 100644 --- a/tests/baselines/reference/jsEnumTagOnObjectFrozen.symbols +++ b/tests/baselines/reference/jsEnumTagOnObjectFrozen.symbols @@ -8,7 +8,9 @@ const { Thing, useThing, cbThing } = require("./index"); useThing(Thing.a); >useThing : Symbol(useThing, Decl(usage.js, 0, 14)) +>Thing.a : Symbol(a, Decl(index.js, 1, 29)) >Thing : Symbol(Thing, Decl(usage.js, 0, 7)) +>a : Symbol(a, Decl(index.js, 1, 29)) /** * @typedef {Object} LogEntry diff --git a/tests/baselines/reference/jsEnumTagOnObjectFrozen.types b/tests/baselines/reference/jsEnumTagOnObjectFrozen.types index df50c0635e268..29eb0b7957357 100644 --- a/tests/baselines/reference/jsEnumTagOnObjectFrozen.types +++ b/tests/baselines/reference/jsEnumTagOnObjectFrozen.types @@ -1,6 +1,6 @@ === tests/cases/compiler/usage.js === const { Thing, useThing, cbThing } = require("./index"); ->Thing : any +>Thing : Readonly<{ a: string; b: string; }> >useThing : (x: string) => void >cbThing : (x: (x: string) => void) => void >require("./index") : typeof import("tests/cases/compiler/index") @@ -10,9 +10,9 @@ const { Thing, useThing, cbThing } = require("./index"); useThing(Thing.a); >useThing(Thing.a) : void >useThing : (x: string) => void ->Thing.a : error ->Thing : any ->a : any +>Thing.a : string +>Thing : Readonly<{ a: string; b: string; }> +>a : string /** * @typedef {Object} LogEntry @@ -66,9 +66,9 @@ const Thing = Object.freeze({ exports.Thing = Thing; >exports.Thing = Thing : Readonly<{ a: string; b: string; }> ->exports.Thing : error +>exports.Thing : Readonly<{ a: string; b: string; }> >exports : typeof import("tests/cases/compiler/index") ->Thing : any +>Thing : Readonly<{ a: string; b: string; }> >Thing : Readonly<{ a: string; b: string; }> /** diff --git a/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementation.errors.txt b/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementation.errors.txt index b05fc6fa6d944..fb0c214ddf657 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementation.errors.txt +++ b/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementation.errors.txt @@ -1,8 +1,6 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. tests/cases/compiler/a.ts(1,10): error TS2393: Duplicate function implementation. -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. ==== tests/cases/compiler/b.js (0 errors) ==== function foo() { return 10; diff --git a/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementation.js b/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementation.js index 9b64450936186..25c804f1088b7 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementation.js +++ b/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementation.js @@ -21,3 +21,5 @@ function foo() { //// [out.d.ts] +declare function foo(): number; +declare function foo(): number; diff --git a/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementationFileOrderReversed.errors.txt b/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementationFileOrderReversed.errors.txt index 82dbc27db0f40..78eb22546e8b0 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementationFileOrderReversed.errors.txt +++ b/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementationFileOrderReversed.errors.txt @@ -1,8 +1,6 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. tests/cases/compiler/a.ts(1,10): error TS2393: Duplicate function implementation. -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. ==== tests/cases/compiler/a.ts (1 errors) ==== function foo() { ~~~ diff --git a/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementationFileOrderReversed.js b/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementationFileOrderReversed.js index d7965e91be1d3..96e2c603a8320 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementationFileOrderReversed.js +++ b/tests/baselines/reference/jsFileCompilationDuplicateFunctionImplementationFileOrderReversed.js @@ -22,3 +22,5 @@ function foo() { //// [out.d.ts] +declare function foo(): number; +declare function foo(): number; diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariable.errors.txt b/tests/baselines/reference/jsFileCompilationDuplicateVariable.errors.txt deleted file mode 100644 index f8ae4a1ba74cd..0000000000000 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariable.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. - - -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. -==== tests/cases/compiler/a.ts (0 errors) ==== - var x = 10; - -==== tests/cases/compiler/b.js (0 errors) ==== - var x = "hello"; // No error is recorded here and declaration file will show this as number \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariable.js b/tests/baselines/reference/jsFileCompilationDuplicateVariable.js index a70637bc7c066..549bd0dfe9a28 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariable.js +++ b/tests/baselines/reference/jsFileCompilationDuplicateVariable.js @@ -4,12 +4,28 @@ var x = 10; //// [b.js] -var x = "hello"; // No error is recorded here and declaration file will show this as number +var x = "hello"; // Error is recorded here, but suppressed because the js file isn't checked //// [out.js] var x = 10; -var x = "hello"; // No error is recorded here and declaration file will show this as number +var x = "hello"; // Error is recorded here, but suppressed because the js file isn't checked //// [out.d.ts] declare var x: number; +declare var x: string; + + +//// [DtsFileErrors] + + +out.d.ts(2,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. + + +==== out.d.ts (1 errors) ==== + declare var x: number; + declare var x: string; + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. +!!! related TS6203 out.d.ts:1:13: 'x' was also declared here. + \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariable.symbols b/tests/baselines/reference/jsFileCompilationDuplicateVariable.symbols index 9bfc61a64f85a..a82dee6bb9344 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariable.symbols +++ b/tests/baselines/reference/jsFileCompilationDuplicateVariable.symbols @@ -3,6 +3,6 @@ var x = 10; >x : Symbol(x, Decl(a.ts, 0, 3), Decl(b.js, 0, 3)) === tests/cases/compiler/b.js === -var x = "hello"; // No error is recorded here and declaration file will show this as number +var x = "hello"; // Error is recorded here, but suppressed because the js file isn't checked >x : Symbol(x, Decl(a.ts, 0, 3), Decl(b.js, 0, 3)) diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariable.types b/tests/baselines/reference/jsFileCompilationDuplicateVariable.types index bcd115b1577b9..bd82bb53df6d0 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariable.types +++ b/tests/baselines/reference/jsFileCompilationDuplicateVariable.types @@ -4,7 +4,7 @@ var x = 10; >10 : 10 === tests/cases/compiler/b.js === -var x = "hello"; // No error is recorded here and declaration file will show this as number +var x = "hello"; // Error is recorded here, but suppressed because the js file isn't checked >x : number >"hello" : "hello" diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.errors.txt b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.errors.txt index 9e46d6225a2c8..540970836d656 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.errors.txt +++ b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.errors.txt @@ -1,13 +1,11 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. tests/cases/compiler/a.ts(1,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'number'. -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. ==== tests/cases/compiler/b.js (0 errors) ==== var x = "hello"; ==== tests/cases/compiler/a.ts (1 errors) ==== - var x = 10; // Error reported so no declaration file generated? + var x = 10; // Error reported ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'number'. !!! related TS6203 tests/cases/compiler/b.js:1:5: 'x' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.js b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.js index fd9da7c71066b..83b33fdd02b4d 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.js +++ b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.js @@ -4,12 +4,13 @@ var x = "hello"; //// [a.ts] -var x = 10; // Error reported so no declaration file generated? +var x = 10; // Error reported //// [out.js] var x = "hello"; -var x = 10; // Error reported so no declaration file generated? +var x = 10; // Error reported //// [out.d.ts] declare var x: string; +declare var x: string; diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.symbols b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.symbols index 0b1360f8f5abe..f6f944c8642bc 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.symbols +++ b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.symbols @@ -3,6 +3,6 @@ var x = "hello"; >x : Symbol(x, Decl(b.js, 0, 3), Decl(a.ts, 0, 3)) === tests/cases/compiler/a.ts === -var x = 10; // Error reported so no declaration file generated? +var x = 10; // Error reported >x : Symbol(x, Decl(b.js, 0, 3), Decl(a.ts, 0, 3)) diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.types b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.types index b88f42f0c28a9..48a2ee9e9ef0a 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.types +++ b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.types @@ -4,7 +4,7 @@ var x = "hello"; >"hello" : "hello" === tests/cases/compiler/a.ts === -var x = 10; // Error reported so no declaration file generated? +var x = 10; // Error reported >x : string >10 : 10 diff --git a/tests/baselines/reference/jsFileCompilationEmitDeclarations.errors.txt b/tests/baselines/reference/jsFileCompilationEmitDeclarations.errors.txt deleted file mode 100644 index 3e89f9c9436f5..0000000000000 --- a/tests/baselines/reference/jsFileCompilationEmitDeclarations.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. - - -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. -==== tests/cases/compiler/a.ts (0 errors) ==== - class c { - } - -==== tests/cases/compiler/b.js (0 errors) ==== - function foo() { - } - \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationEmitDeclarations.js b/tests/baselines/reference/jsFileCompilationEmitDeclarations.js index 312f3b6b22953..2671a580cbc7e 100644 --- a/tests/baselines/reference/jsFileCompilationEmitDeclarations.js +++ b/tests/baselines/reference/jsFileCompilationEmitDeclarations.js @@ -22,3 +22,4 @@ function foo() { //// [out.d.ts] declare class c { } +declare function foo(): void; diff --git a/tests/baselines/reference/jsFileCompilationEmitTrippleSlashReference.errors.txt b/tests/baselines/reference/jsFileCompilationEmitTrippleSlashReference.errors.txt deleted file mode 100644 index 0cefa2eedac20..0000000000000 --- a/tests/baselines/reference/jsFileCompilationEmitTrippleSlashReference.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. - - -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. -==== tests/cases/compiler/a.ts (0 errors) ==== - class c { - } - -==== tests/cases/compiler/b.js (0 errors) ==== - /// - function foo() { - } - -==== tests/cases/compiler/c.js (0 errors) ==== - function bar() { - } \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationEmitTrippleSlashReference.js b/tests/baselines/reference/jsFileCompilationEmitTrippleSlashReference.js index 625c09964c065..128ec0c3e357e 100644 --- a/tests/baselines/reference/jsFileCompilationEmitTrippleSlashReference.js +++ b/tests/baselines/reference/jsFileCompilationEmitTrippleSlashReference.js @@ -29,3 +29,5 @@ function foo() { //// [out.d.ts] declare class c { } +declare function bar(): void; +declare function foo(): void; diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt index c9937ecd3592e..b19009a468b97 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.errors.txt @@ -1,9 +1,7 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. error TS5055: Cannot write file 'tests/cases/compiler/c.js' because it would overwrite input file. Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. !!! error TS5055: Cannot write file 'tests/cases/compiler/c.js' because it would overwrite input file. !!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. ==== tests/cases/compiler/a.ts (0 errors) ==== @@ -12,7 +10,7 @@ error TS5055: Cannot write file 'tests/cases/compiler/c.js' because it would ove ==== tests/cases/compiler/b.ts (0 errors) ==== /// - // b.d.ts should have c.js as the reference path since we dont emit declarations for js files + // b.d.ts should have c.d.ts as the reference path function foo() { } diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.js b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.js index f9dcb3b2f71a8..7a0942b5ac718 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.js +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.js @@ -6,7 +6,7 @@ class c { //// [b.ts] /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files +// b.d.ts should have c.d.ts as the reference path function foo() { } @@ -22,7 +22,7 @@ var c = /** @class */ (function () { }()); //// [b.js] /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files +// b.d.ts should have c.d.ts as the reference path function foo() { } @@ -30,6 +30,8 @@ function foo() { //// [a.d.ts] declare class c { } +//// [c.d.ts] +declare function bar(): void; //// [b.d.ts] -/// +/// declare function foo(): void; diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.symbols b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.symbols index 424fd85c16587..7f3b8e3c6f158 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.symbols +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.symbols @@ -5,7 +5,7 @@ class c { === tests/cases/compiler/b.ts === /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files +// b.d.ts should have c.d.ts as the reference path function foo() { >foo : Symbol(foo, Decl(b.ts, 0, 0)) } diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.types b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.types index f8b82383ac47c..5ef6333da21c0 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.types +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.types @@ -5,7 +5,7 @@ class c { === tests/cases/compiler/b.ts === /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files +// b.d.ts should have c.d.ts as the reference path function foo() { >foo : () => void } diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.errors.txt b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.errors.txt deleted file mode 100644 index 441514014799d..0000000000000 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. - - -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. -==== tests/cases/compiler/a.ts (0 errors) ==== - class c { - } - -==== tests/cases/compiler/b.ts (0 errors) ==== - /// - // error on above reference when emitting declarations - function foo() { - } - -==== tests/cases/compiler/c.js (0 errors) ==== - function bar() { - } \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.js b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.js index e10b3e43fb854..9c60af0c79c06 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.js +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.js @@ -6,7 +6,6 @@ class c { //// [b.ts] /// -// error on above reference when emitting declarations function foo() { } @@ -23,13 +22,12 @@ var c = /** @class */ (function () { function bar() { } /// -// error on above reference when emitting declarations function foo() { } //// [out.d.ts] -/// declare class c { } +declare function bar(): void; declare function foo(): void; diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.symbols b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.symbols index 544fe53f425af..967d023d2c2f8 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.symbols +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.symbols @@ -5,7 +5,6 @@ class c { === tests/cases/compiler/b.ts === /// -// error on above reference when emitting declarations function foo() { >foo : Symbol(foo, Decl(b.ts, 0, 0)) } diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.types b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.types index 8aafb9f61d034..b34de54d704f8 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.types +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.types @@ -5,7 +5,6 @@ class c { === tests/cases/compiler/b.ts === /// -// error on above reference when emitting declarations function foo() { >foo : () => void } diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.errors.txt b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.errors.txt deleted file mode 100644 index fb6c801b42e7c..0000000000000 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. - - -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. -==== tests/cases/compiler/a.ts (0 errors) ==== - class c { - } - -==== tests/cases/compiler/b.ts (0 errors) ==== - /// - // b.d.ts should have c.js as the reference path since we dont emit declarations for js files - function foo() { - } - -==== tests/cases/compiler/c.js (0 errors) ==== - function bar() { - } \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.js b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.js index 5e12d775bb139..fe570fb330791 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.js +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.js @@ -6,7 +6,6 @@ class c { //// [b.ts] /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files function foo() { } @@ -25,7 +24,6 @@ function bar() { } //// [b.js] /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files function foo() { } @@ -33,6 +31,8 @@ function foo() { //// [a.d.ts] declare class c { } +//// [c.d.ts] +declare function bar(): void; //// [b.d.ts] -/// +/// declare function foo(): void; diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.symbols b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.symbols index 424fd85c16587..967d023d2c2f8 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.symbols +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.symbols @@ -5,7 +5,6 @@ class c { === tests/cases/compiler/b.ts === /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files function foo() { >foo : Symbol(foo, Decl(b.ts, 0, 0)) } diff --git a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.types b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.types index f8b82383ac47c..b34de54d704f8 100644 --- a/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.types +++ b/tests/baselines/reference/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.types @@ -5,7 +5,6 @@ class c { === tests/cases/compiler/b.ts === /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files function foo() { >foo : () => void } diff --git a/tests/baselines/reference/jsFileCompilationLetDeclarationOrder.errors.txt b/tests/baselines/reference/jsFileCompilationLetDeclarationOrder.errors.txt deleted file mode 100644 index 20a9c81ea9c62..0000000000000 --- a/tests/baselines/reference/jsFileCompilationLetDeclarationOrder.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. - - -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. -==== tests/cases/compiler/b.js (0 errors) ==== - let a = 10; - b = 30; - -==== tests/cases/compiler/a.ts (0 errors) ==== - let b = 30; - a = 10; - \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationLetDeclarationOrder.js b/tests/baselines/reference/jsFileCompilationLetDeclarationOrder.js index 16e4b7a3011f2..15a1e8d753354 100644 --- a/tests/baselines/reference/jsFileCompilationLetDeclarationOrder.js +++ b/tests/baselines/reference/jsFileCompilationLetDeclarationOrder.js @@ -17,4 +17,5 @@ a = 10; //// [out.d.ts] +declare let a: number; declare let b: number; diff --git a/tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.errors.txt b/tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.errors.txt index 6fc8df185006c..4ffbabdd06394 100644 --- a/tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.errors.txt +++ b/tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.errors.txt @@ -1,8 +1,6 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. tests/cases/compiler/a.ts(2,1): error TS2448: Block-scoped variable 'a' used before its declaration. -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. ==== tests/cases/compiler/a.ts (1 errors) ==== let b = 30; a = 10; diff --git a/tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.js b/tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.js index 890b1c22f717e..641a89c1c5049 100644 --- a/tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.js +++ b/tests/baselines/reference/jsFileCompilationLetDeclarationOrder2.js @@ -17,3 +17,4 @@ b = 30; //// [out.d.ts] declare let b: number; +declare let a: number; diff --git a/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.errors.txt b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.errors.txt deleted file mode 100644 index 7133188adc0ca..0000000000000 --- a/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -error TS5053: Option 'allowJs' cannot be specified with option 'composite'. - - -!!! error TS5053: Option 'allowJs' cannot be specified with option 'composite'. -==== tests/cases/compiler/a.ts (0 errors) ==== - class c { - } - -==== tests/cases/compiler/b.js (0 errors) ==== - function foo() { - } - \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.js b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.js index e34edb10ff426..9a1dbcd530140 100644 --- a/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.js +++ b/tests/baselines/reference/jsFileCompilationWithEnabledCompositeOption.js @@ -22,3 +22,4 @@ function foo() { //// [out.d.ts] declare class c { } +declare function foo(): void; diff --git a/tests/baselines/reference/jsdocImportType.types b/tests/baselines/reference/jsdocImportType.types index a5d3844388a4c..66b01b1a5c75d 100644 --- a/tests/baselines/reference/jsdocImportType.types +++ b/tests/baselines/reference/jsdocImportType.types @@ -3,26 +3,26 @@ /** @typedef {import("./mod1")} C * @type {C} */ var c; ->c : Chunk +>c : import("tests/cases/conformance/jsdoc/mod1") c.chunk; >c.chunk : number ->c : Chunk +>c : import("tests/cases/conformance/jsdoc/mod1") >chunk : number const D = require("./mod1"); ->D : typeof Chunk ->require("./mod1") : typeof Chunk +>D : typeof import("tests/cases/conformance/jsdoc/mod1") +>require("./mod1") : typeof import("tests/cases/conformance/jsdoc/mod1") >require : (name: string) => any >"./mod1" : "./mod1" /** @type {D} */ var d; ->d : Chunk +>d : import("tests/cases/conformance/jsdoc/mod1") d.chunk; >d.chunk : number ->d : Chunk +>d : import("tests/cases/conformance/jsdoc/mod1") >chunk : number === tests/cases/conformance/jsdoc/types.d.ts === diff --git a/tests/baselines/reference/jsdocImportType2.types b/tests/baselines/reference/jsdocImportType2.types index 817b754069aae..a75c4fa0738f9 100644 --- a/tests/baselines/reference/jsdocImportType2.types +++ b/tests/baselines/reference/jsdocImportType2.types @@ -3,26 +3,26 @@ /** @typedef {import("./mod1")} C * @type {C} */ var c; ->c : Chunk +>c : import("tests/cases/conformance/jsdoc/mod1") c.chunk; >c.chunk : number ->c : Chunk +>c : import("tests/cases/conformance/jsdoc/mod1") >chunk : number const D = require("./mod1"); ->D : typeof Chunk ->require("./mod1") : typeof Chunk +>D : typeof import("tests/cases/conformance/jsdoc/mod1") +>require("./mod1") : typeof import("tests/cases/conformance/jsdoc/mod1") >require : (name: string) => any >"./mod1" : "./mod1" /** @type {D} */ var d; ->d : Chunk +>d : import("tests/cases/conformance/jsdoc/mod1") d.chunk; >d.chunk : number ->d : Chunk +>d : import("tests/cases/conformance/jsdoc/mod1") >chunk : number === tests/cases/conformance/jsdoc/types.d.ts === @@ -40,12 +40,12 @@ declare var module: { exports: any }; === tests/cases/conformance/jsdoc/mod1.js === /// module.exports = class Chunk { ->module.exports = class Chunk { constructor() { this.chunk = 1; }} : typeof Chunk ->module.exports : typeof Chunk ->module : { "tests/cases/conformance/jsdoc/mod1": typeof Chunk; } ->exports : typeof Chunk ->class Chunk { constructor() { this.chunk = 1; }} : typeof Chunk ->Chunk : typeof Chunk +>module.exports = class Chunk { constructor() { this.chunk = 1; }} : typeof import("tests/cases/conformance/jsdoc/mod1") +>module.exports : typeof import("tests/cases/conformance/jsdoc/mod1") +>module : { "tests/cases/conformance/jsdoc/mod1": typeof import("tests/cases/conformance/jsdoc/mod1"); } +>exports : typeof import("tests/cases/conformance/jsdoc/mod1") +>class Chunk { constructor() { this.chunk = 1; }} : typeof import("tests/cases/conformance/jsdoc/mod1") +>Chunk : typeof import("tests/cases/conformance/jsdoc/mod1") constructor() { this.chunk = 1; diff --git a/tests/baselines/reference/moduleAugmentationDuringSyntheticDefaultCheck.symbols b/tests/baselines/reference/moduleAugmentationDuringSyntheticDefaultCheck.symbols index 115bb3b1a2c2c..4025c6c5e6066 100644 --- a/tests/baselines/reference/moduleAugmentationDuringSyntheticDefaultCheck.symbols +++ b/tests/baselines/reference/moduleAugmentationDuringSyntheticDefaultCheck.symbols @@ -8,7 +8,7 @@ import moment = require("moment-timezone"); declare function moment(): moment.Moment; >moment : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) >moment : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41)) ->Moment : Symbol(Moment, Decl(index.d.ts, 1, 26)) +>Moment : Symbol(moment.Moment, Decl(index.d.ts, 1, 26)) declare namespace moment { >moment : Symbol(moment, Decl(index.d.ts, 0, 0), Decl(index.d.ts, 0, 41), Decl(idx.ts, 0, 34), Decl(index.d.ts, 1, 16)) diff --git a/tests/baselines/reference/moduleAugmentationOfAlias.types b/tests/baselines/reference/moduleAugmentationOfAlias.types index a5112f5869588..671948611b021 100644 --- a/tests/baselines/reference/moduleAugmentationOfAlias.types +++ b/tests/baselines/reference/moduleAugmentationOfAlias.types @@ -1,7 +1,7 @@ === /a.ts === interface I {} export default I; ->I : I +>I : import("/a").default === /b.ts === export {}; diff --git a/tests/baselines/reference/moduleExportAlias2.types b/tests/baselines/reference/moduleExportAlias2.types index 65f245a6f4f32..0449561a9d879 100644 --- a/tests/baselines/reference/moduleExportAlias2.types +++ b/tests/baselines/reference/moduleExportAlias2.types @@ -1,8 +1,8 @@ === tests/cases/conformance/salsa/index.js === /// const C = require("./semver") ->C : typeof C ->require("./semver") : typeof C +>C : typeof import("tests/cases/conformance/salsa/semver") +>require("./semver") : typeof import("tests/cases/conformance/salsa/semver") >require : (name: string) => any >"./semver" : "./semver" @@ -10,14 +10,14 @@ var two = C.f(1) >two : any >C.f(1) : any >C.f : (n: any) => any ->C : typeof C +>C : typeof import("tests/cases/conformance/salsa/semver") >f : (n: any) => any >1 : 1 var c = new C ->c : C ->new C : C ->C : typeof C +>c : import("tests/cases/conformance/salsa/semver") +>new C : import("tests/cases/conformance/salsa/semver") +>C : typeof import("tests/cases/conformance/salsa/semver") === tests/cases/conformance/salsa/node.d.ts === declare function require(name: string): any; diff --git a/tests/baselines/reference/moduleExportAlias4.types b/tests/baselines/reference/moduleExportAlias4.types index 744252781400b..1a16b5a09cdee 100644 --- a/tests/baselines/reference/moduleExportAlias4.types +++ b/tests/baselines/reference/moduleExportAlias4.types @@ -1,25 +1,25 @@ === tests/cases/conformance/salsa/bug24024.js === // #24024 var wat = require('./bug24024') ->wat : typeof C ->require('./bug24024') : typeof C +>wat : typeof import("tests/cases/conformance/salsa/bug24024") +>require('./bug24024') : typeof import("tests/cases/conformance/salsa/bug24024") >require : any >'./bug24024' : "./bug24024" module.exports = class C {} ->module.exports = class C {} : typeof C ->module.exports : typeof C ->module : { "tests/cases/conformance/salsa/bug24024": typeof C; } ->exports : typeof C ->class C {} : typeof C ->C : typeof C +>module.exports = class C {} : typeof import("tests/cases/conformance/salsa/bug24024") +>module.exports : typeof import("tests/cases/conformance/salsa/bug24024") +>module : { "tests/cases/conformance/salsa/bug24024": typeof import("tests/cases/conformance/salsa/bug24024"); } +>exports : typeof import("tests/cases/conformance/salsa/bug24024") +>class C {} : typeof import("tests/cases/conformance/salsa/bug24024") +>C : typeof import("tests/cases/conformance/salsa/bug24024") module.exports.D = class D { } >module.exports.D = class D { } : typeof D >module.exports.D : typeof D ->module.exports : typeof C ->module : { "tests/cases/conformance/salsa/bug24024": typeof C; } ->exports : typeof C +>module.exports : typeof import("tests/cases/conformance/salsa/bug24024") +>module : { "tests/cases/conformance/salsa/bug24024": typeof import("tests/cases/conformance/salsa/bug24024"); } +>exports : typeof import("tests/cases/conformance/salsa/bug24024") >D : typeof D >class D { } : typeof D >D : typeof D diff --git a/tests/baselines/reference/moduleExportPropertyAssignmentDefault.types b/tests/baselines/reference/moduleExportPropertyAssignmentDefault.types index a2f69a87f280b..cc78e2681bf9c 100644 --- a/tests/baselines/reference/moduleExportPropertyAssignmentDefault.types +++ b/tests/baselines/reference/moduleExportPropertyAssignmentDefault.types @@ -1,21 +1,21 @@ === tests/cases/conformance/salsa/axios.js === var axios = {} ->axios : { default: { default: any; }; } +>axios : typeof axios >{} : {} module.exports = axios // both assignments should be ok ->module.exports = axios : { default: { default: any; }; } ->module.exports : { default: { default: any; }; } ->module : { "tests/cases/conformance/salsa/axios": { default: { default: any; }; }; } ->exports : { default: { default: any; }; } ->axios : { default: { default: any; }; } +>module.exports = axios : typeof axios +>module.exports : typeof axios +>module : { "tests/cases/conformance/salsa/axios": typeof axios; } +>exports : typeof axios +>axios : typeof axios module.exports.default = axios ->module.exports.default = axios : { default: { default: any; }; } ->module.exports.default : { default: any; } ->module.exports : { default: { default: any; }; } ->module : { "tests/cases/conformance/salsa/axios": { default: { default: any; }; }; } ->exports : { default: { default: any; }; } ->default : { default: any; } ->axios : { default: { default: any; }; } +>module.exports.default = axios : typeof axios +>module.exports.default : typeof axios +>module.exports : typeof axios +>module : { "tests/cases/conformance/salsa/axios": typeof axios; } +>exports : typeof axios +>default : typeof axios +>axios : typeof axios diff --git a/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.symbols b/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.symbols index edb7d52254a46..ad04485687004 100644 --- a/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.symbols +++ b/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.symbols @@ -42,10 +42,10 @@ declare function require(name: string): any; /// module.exports.bothBefore = 'string' >module.exports.bothBefore : Symbol(bothBefore) ->module.exports : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) +>module.exports : Symbol(bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) >module : Symbol(module, Decl(mod1.js, 0, 0)) >exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0)) ->bothBefore : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) +>bothBefore : Symbol(bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) A.justExport = 4 >A.justExport : Symbol(A.justExport, Decl(mod1.js, 1, 36)) @@ -53,14 +53,14 @@ A.justExport = 4 >justExport : Symbol(A.justExport, Decl(mod1.js, 1, 36)) A.bothBefore = 2 ->A.bothBefore : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) +>A.bothBefore : Symbol(bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) >A : Symbol(A, Decl(mod1.js, 5, 18), Decl(mod1.js, 1, 36), Decl(mod1.js, 2, 16), Decl(mod1.js, 3, 16)) ->bothBefore : Symbol(A.bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) +>bothBefore : Symbol(bothBefore, Decl(mod1.js, 2, 16), Decl(mod1.js, 0, 0)) A.bothAfter = 3 ->A.bothAfter : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) +>A.bothAfter : Symbol(bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) >A : Symbol(A, Decl(mod1.js, 5, 18), Decl(mod1.js, 1, 36), Decl(mod1.js, 2, 16), Decl(mod1.js, 3, 16)) ->bothAfter : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) +>bothAfter : Symbol(bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) module.exports = A >module.exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0)) @@ -76,10 +76,10 @@ function A() { } module.exports.bothAfter = 'string' >module.exports.bothAfter : Symbol(bothAfter) ->module.exports : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) +>module.exports : Symbol(bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) >module : Symbol(module, Decl(mod1.js, 0, 0)) >exports : Symbol("tests/cases/conformance/salsa/mod1", Decl(mod1.js, 0, 0)) ->bothAfter : Symbol(A.bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) +>bothAfter : Symbol(bothAfter, Decl(mod1.js, 3, 16), Decl(mod1.js, 8, 1)) module.exports.justProperty = 'string' >module.exports.justProperty : Symbol(justProperty) diff --git a/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.types b/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.types index 8c55a664fc2e9..67285b7a29631 100644 --- a/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.types +++ b/tests/baselines/reference/moduleExportWithExportPropertyAssignment4.types @@ -1,8 +1,8 @@ === tests/cases/conformance/salsa/a.js === /// var mod1 = require('./mod1') ->mod1 : typeof A ->require('./mod1') : typeof A +>mod1 : typeof import("tests/cases/conformance/salsa/mod1") +>require('./mod1') : typeof import("tests/cases/conformance/salsa/mod1") >require : (name: string) => any >'./mod1' : "./mod1" @@ -10,7 +10,7 @@ mod1.justExport.toFixed() >mod1.justExport.toFixed() : string >mod1.justExport.toFixed : (fractionDigits?: number) => string >mod1.justExport : number ->mod1 : typeof A +>mod1 : typeof import("tests/cases/conformance/salsa/mod1") >justExport : number >toFixed : (fractionDigits?: number) => string @@ -18,7 +18,7 @@ mod1.bothBefore.toFixed() // error >mod1.bothBefore.toFixed() : any >mod1.bothBefore.toFixed : any >mod1.bothBefore : string | number ->mod1 : typeof A +>mod1 : typeof import("tests/cases/conformance/salsa/mod1") >bothBefore : string | number >toFixed : any @@ -26,14 +26,14 @@ mod1.bothAfter.toFixed() >mod1.bothAfter.toFixed() : any >mod1.bothAfter.toFixed : any >mod1.bothAfter : string | number ->mod1 : typeof A +>mod1 : typeof import("tests/cases/conformance/salsa/mod1") >bothAfter : string | number >toFixed : any mod1.justProperty.length >mod1.justProperty.length : number >mod1.justProperty : string ->mod1 : typeof A +>mod1 : typeof import("tests/cases/conformance/salsa/mod1") >justProperty : string >length : number diff --git a/tests/baselines/reference/multiImportExport.types b/tests/baselines/reference/multiImportExport.types index 4a94eef9865ed..302af2ccc72c3 100644 --- a/tests/baselines/reference/multiImportExport.types +++ b/tests/baselines/reference/multiImportExport.types @@ -3,17 +3,17 @@ import Drawing = require('./Drawing'); >Drawing : typeof Drawing var addr = new Drawing.Math.Adder(); ->addr : Adder ->new Drawing.Math.Adder() : Adder ->Drawing.Math.Adder : typeof Adder ->Drawing.Math : { Adder: typeof Adder; } +>addr : import("tests/cases/compiler/Math/Adder") +>new Drawing.Math.Adder() : import("tests/cases/compiler/Math/Adder") +>Drawing.Math.Adder : typeof import("tests/cases/compiler/Math/Adder") +>Drawing.Math : { Adder: typeof import("tests/cases/compiler/Math/Adder"); } >Drawing : typeof Drawing ->Math : { Adder: typeof Adder; } ->Adder : typeof Adder +>Math : { Adder: typeof import("tests/cases/compiler/Math/Adder"); } +>Adder : typeof import("tests/cases/compiler/Math/Adder") === tests/cases/compiler/Drawing.ts === export import Math = require('./Math/Math') ->Math : { Adder: typeof Adder; } +>Math : { Adder: typeof import("tests/cases/compiler/Math/Adder"); } === tests/cases/compiler/Math/Math.ts === import Adder = require('./Adder'); diff --git a/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.js b/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.js new file mode 100644 index 0000000000000..74db93cc681a4 --- /dev/null +++ b/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.js @@ -0,0 +1,57 @@ +//// [tests/cases/compiler/namespacesWithTypeAliasOnlyExportsMerge.ts] //// + +//// [constAndNS.ts] +type A = number; +declare const Q: number; +declare namespace Q { + export { A }; +} +declare const try1: Q.A; +declare namespace Q2 { + export { Q } +} +declare const try2: Q2.Q.A; +declare namespace Q3 { + export {A as B}; +} +declare const try3: Q3.B; +declare namespace Q4 { + export { Q as default }; +} +declare const try4: Q4.default.A; +export {}; +//// [circular.ts] +declare namespace NS1 { + export { NS2 }; +} +declare namespace NS2 { + export { NS1 }; +} +export {}; +//// [circularWithUses.ts] +type A = string; +type B = number; +declare namespace NS1 { + export { NS2, A }; +} +declare namespace NS2 { + export { NS1, B }; +} +export {}; +declare const try1: NS1.A; +declare const try2: NS2.B; +declare const try3: NS1.NS2.B; +declare const try4: NS2.NS1.A; +declare const try5: NS1.NS2.NS1.A; +declare const try6: NS2.NS1.NS2.B; + + +//// [constAndNS.js] +"use strict"; +exports.__esModule = true; +//// [circular.js] +"use strict"; +exports.__esModule = true; +//// [circularWithUses.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.symbols b/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.symbols new file mode 100644 index 0000000000000..1682662e55db7 --- /dev/null +++ b/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.symbols @@ -0,0 +1,128 @@ +=== tests/cases/compiler/constAndNS.ts === +type A = number; +>A : Symbol(A, Decl(constAndNS.ts, 0, 0)) + +declare const Q: number; +>Q : Symbol(Q, Decl(constAndNS.ts, 1, 13), Decl(constAndNS.ts, 1, 24)) + +declare namespace Q { +>Q : Symbol(Q, Decl(constAndNS.ts, 1, 13), Decl(constAndNS.ts, 1, 24)) + + export { A }; +>A : Symbol(A, Decl(constAndNS.ts, 3, 12)) +} +declare const try1: Q.A; +>try1 : Symbol(try1, Decl(constAndNS.ts, 5, 13)) +>Q : Symbol(Q, Decl(constAndNS.ts, 1, 13), Decl(constAndNS.ts, 1, 24)) +>A : Symbol(Q.A, Decl(constAndNS.ts, 3, 12)) + +declare namespace Q2 { +>Q2 : Symbol(Q2, Decl(constAndNS.ts, 5, 24)) + + export { Q } +>Q : Symbol(Q, Decl(constAndNS.ts, 7, 12)) +} +declare const try2: Q2.Q.A; +>try2 : Symbol(try2, Decl(constAndNS.ts, 9, 13)) +>Q2 : Symbol(Q2, Decl(constAndNS.ts, 5, 24)) +>Q : Symbol(Q2.Q, Decl(constAndNS.ts, 7, 12)) +>A : Symbol(Q.A, Decl(constAndNS.ts, 3, 12)) + +declare namespace Q3 { +>Q3 : Symbol(Q3, Decl(constAndNS.ts, 9, 27)) + + export {A as B}; +>A : Symbol(A, Decl(constAndNS.ts, 0, 0)) +>B : Symbol(B, Decl(constAndNS.ts, 11, 12)) +} +declare const try3: Q3.B; +>try3 : Symbol(try3, Decl(constAndNS.ts, 13, 13)) +>Q3 : Symbol(Q3, Decl(constAndNS.ts, 9, 27)) +>B : Symbol(Q3.B, Decl(constAndNS.ts, 11, 12)) + +declare namespace Q4 { +>Q4 : Symbol(Q4, Decl(constAndNS.ts, 13, 25)) + + export { Q as default }; +>Q : Symbol(Q, Decl(constAndNS.ts, 1, 13), Decl(constAndNS.ts, 1, 24)) +>default : Symbol(default, Decl(constAndNS.ts, 15, 12)) +} +declare const try4: Q4.default.A; +>try4 : Symbol(try4, Decl(constAndNS.ts, 17, 13)) +>Q4 : Symbol(Q4, Decl(constAndNS.ts, 13, 25)) +>default : Symbol(Q4.default, Decl(constAndNS.ts, 15, 12)) +>A : Symbol(Q.A, Decl(constAndNS.ts, 3, 12)) + +export {}; +=== tests/cases/compiler/circular.ts === +declare namespace NS1 { +>NS1 : Symbol(NS1, Decl(circular.ts, 0, 0)) + + export { NS2 }; +>NS2 : Symbol(NS2, Decl(circular.ts, 1, 12)) +} +declare namespace NS2 { +>NS2 : Symbol(NS2, Decl(circular.ts, 2, 1)) + + export { NS1 }; +>NS1 : Symbol(NS1, Decl(circular.ts, 4, 12)) +} +export {}; +=== tests/cases/compiler/circularWithUses.ts === +type A = string; +>A : Symbol(A, Decl(circularWithUses.ts, 0, 0)) + +type B = number; +>B : Symbol(B, Decl(circularWithUses.ts, 0, 16)) + +declare namespace NS1 { +>NS1 : Symbol(NS1, Decl(circularWithUses.ts, 1, 16)) + + export { NS2, A }; +>NS2 : Symbol(NS2, Decl(circularWithUses.ts, 3, 12)) +>A : Symbol(A, Decl(circularWithUses.ts, 3, 17)) +} +declare namespace NS2 { +>NS2 : Symbol(NS2, Decl(circularWithUses.ts, 4, 1)) + + export { NS1, B }; +>NS1 : Symbol(NS1, Decl(circularWithUses.ts, 6, 12)) +>B : Symbol(B, Decl(circularWithUses.ts, 6, 17)) +} +export {}; +declare const try1: NS1.A; +>try1 : Symbol(try1, Decl(circularWithUses.ts, 9, 13)) +>NS1 : Symbol(NS1, Decl(circularWithUses.ts, 1, 16)) +>A : Symbol(NS1.A, Decl(circularWithUses.ts, 3, 17)) + +declare const try2: NS2.B; +>try2 : Symbol(try2, Decl(circularWithUses.ts, 10, 13)) +>NS2 : Symbol(NS2, Decl(circularWithUses.ts, 4, 1)) +>B : Symbol(NS2.B, Decl(circularWithUses.ts, 6, 17)) + +declare const try3: NS1.NS2.B; +>try3 : Symbol(try3, Decl(circularWithUses.ts, 11, 13)) +>NS1 : Symbol(NS1, Decl(circularWithUses.ts, 1, 16)) +>NS2 : Symbol(NS1.NS2, Decl(circularWithUses.ts, 3, 12)) +>B : Symbol(NS2.B, Decl(circularWithUses.ts, 6, 17)) + +declare const try4: NS2.NS1.A; +>try4 : Symbol(try4, Decl(circularWithUses.ts, 12, 13)) +>NS2 : Symbol(NS2, Decl(circularWithUses.ts, 4, 1)) +>NS1 : Symbol(NS2.NS1, Decl(circularWithUses.ts, 6, 12)) +>A : Symbol(NS1.A, Decl(circularWithUses.ts, 3, 17)) + +declare const try5: NS1.NS2.NS1.A; +>try5 : Symbol(try5, Decl(circularWithUses.ts, 13, 13)) +>NS1 : Symbol(NS1, Decl(circularWithUses.ts, 1, 16)) +>NS2 : Symbol(NS1.NS2, Decl(circularWithUses.ts, 3, 12)) +>NS1 : Symbol(NS2.NS1, Decl(circularWithUses.ts, 6, 12)) +>A : Symbol(NS1.A, Decl(circularWithUses.ts, 3, 17)) + +declare const try6: NS2.NS1.NS2.B; +>try6 : Symbol(try6, Decl(circularWithUses.ts, 14, 13)) +>NS2 : Symbol(NS2, Decl(circularWithUses.ts, 4, 1)) +>NS1 : Symbol(NS2.NS1, Decl(circularWithUses.ts, 6, 12)) +>NS2 : Symbol(NS1.NS2, Decl(circularWithUses.ts, 3, 12)) +>B : Symbol(NS2.B, Decl(circularWithUses.ts, 6, 17)) + diff --git a/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.types b/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.types new file mode 100644 index 0000000000000..0b16ca84494ad --- /dev/null +++ b/tests/baselines/reference/namespacesWithTypeAliasOnlyExportsMerge.types @@ -0,0 +1,106 @@ +=== tests/cases/compiler/constAndNS.ts === +type A = number; +>A : number + +declare const Q: number; +>Q : number + +declare namespace Q { + export { A }; +>A : any +} +declare const try1: Q.A; +>try1 : number +>Q : any + +declare namespace Q2 { +>Q2 : typeof Q2 + + export { Q } +>Q : number +} +declare const try2: Q2.Q.A; +>try2 : number +>Q2 : any +>Q : any + +declare namespace Q3 { + export {A as B}; +>A : any +>B : any +} +declare const try3: Q3.B; +>try3 : number +>Q3 : any + +declare namespace Q4 { +>Q4 : typeof Q4 + + export { Q as default }; +>Q : number +>default : number +} +declare const try4: Q4.default.A; +>try4 : number +>Q4 : any +>default : any + +export {}; +=== tests/cases/compiler/circular.ts === +declare namespace NS1 { + export { NS2 }; +>NS2 : any +} +declare namespace NS2 { + export { NS1 }; +>NS1 : any +} +export {}; +=== tests/cases/compiler/circularWithUses.ts === +type A = string; +>A : string + +type B = number; +>B : number + +declare namespace NS1 { + export { NS2, A }; +>NS2 : any +>A : any +} +declare namespace NS2 { + export { NS1, B }; +>NS1 : any +>B : any +} +export {}; +declare const try1: NS1.A; +>try1 : string +>NS1 : any + +declare const try2: NS2.B; +>try2 : number +>NS2 : any + +declare const try3: NS1.NS2.B; +>try3 : number +>NS1 : any +>NS2 : any + +declare const try4: NS2.NS1.A; +>try4 : string +>NS2 : any +>NS1 : any + +declare const try5: NS1.NS2.NS1.A; +>try5 : string +>NS1 : any +>NS2 : any +>NS1 : any + +declare const try6: NS2.NS1.NS2.B; +>try6 : number +>NS2 : any +>NS1 : any +>NS2 : any + diff --git a/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.js b/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.js new file mode 100644 index 0000000000000..fa06a67d93b73 --- /dev/null +++ b/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.js @@ -0,0 +1,17 @@ +//// [noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts] +const cat = 12; +class Foo {} +export = Foo; +declare namespace Foo { + export { cat }; +} + +//// [noCircularDefinitionOnExportOfPrivateInMergedNamespace.js] +"use strict"; +var cat = 12; +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +module.exports = Foo; diff --git a/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.symbols b/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.symbols new file mode 100644 index 0000000000000..5a37b64cd46eb --- /dev/null +++ b/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts === +const cat = 12; +>cat : Symbol(cat, Decl(noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts, 0, 5)) + +class Foo {} +>Foo : Symbol(Foo, Decl(noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts, 0, 15), Decl(noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts, 2, 13)) + +export = Foo; +>Foo : Symbol(Foo, Decl(noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts, 0, 15), Decl(noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts, 2, 13)) + +declare namespace Foo { +>Foo : Symbol(Foo, Decl(noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts, 0, 15), Decl(noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts, 2, 13)) + + export { cat }; +>cat : Symbol(cat, Decl(noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts, 4, 12)) +} diff --git a/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.types b/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.types new file mode 100644 index 0000000000000..5b1a72b6db794 --- /dev/null +++ b/tests/baselines/reference/noCircularDefinitionOnExportOfPrivateInMergedNamespace.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts === +const cat = 12; +>cat : 12 +>12 : 12 + +class Foo {} +>Foo : Foo + +export = Foo; +>Foo : Foo + +declare namespace Foo { +>Foo : typeof Foo + + export { cat }; +>cat : 12 +} diff --git a/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/amd/test.d.ts b/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/amd/test.d.ts index 4c0b8989316ef..bbae04a30bf94 100644 --- a/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/amd/test.d.ts +++ b/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/amd/test.d.ts @@ -1 +1,2 @@ declare var test: number; +declare var test2: number; diff --git a/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/node/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs.errors.txt b/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/node/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs.errors.txt index 6a3c9863cc590..5471371449aa1 100644 --- a/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/node/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs.errors.txt +++ b/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/node/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs.errors.txt @@ -1,16 +1,13 @@ DifferentNamesNotSpecifiedWithAllowJs/tsconfig.json(3,5): error TS6082: Only 'amd' and 'system' modules are supported alongside --out. -DifferentNamesNotSpecifiedWithAllowJs/tsconfig.json(4,5): error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. -==== DifferentNamesNotSpecifiedWithAllowJs/tsconfig.json (2 errors) ==== +==== DifferentNamesNotSpecifiedWithAllowJs/tsconfig.json (1 errors) ==== { "compilerOptions": { "out": "test.js", ~~~~~ !!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out. "allowJs": true - ~~~~~~~~~ -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. } } ==== DifferentNamesNotSpecifiedWithAllowJs/a.ts (0 errors) ==== diff --git a/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/node/test.d.ts b/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/node/test.d.ts index 4c0b8989316ef..bbae04a30bf94 100644 --- a/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/node/test.d.ts +++ b/tests/baselines/reference/project/jsFileCompilationDifferentNamesNotSpecifiedWithAllowJs/node/test.d.ts @@ -1 +1,2 @@ declare var test: number; +declare var test2: number; diff --git a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/amd/test.d.ts b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/amd/test.d.ts index 4c0b8989316ef..bbae04a30bf94 100644 --- a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/amd/test.d.ts +++ b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/amd/test.d.ts @@ -1 +1,2 @@ declare var test: number; +declare var test2: number; diff --git a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/node/jsFileCompilationDifferentNamesSpecifiedWithAllowJs.errors.txt b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/node/jsFileCompilationDifferentNamesSpecifiedWithAllowJs.errors.txt index c2849fae3a580..3c80f199817ad 100644 --- a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/node/jsFileCompilationDifferentNamesSpecifiedWithAllowJs.errors.txt +++ b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/node/jsFileCompilationDifferentNamesSpecifiedWithAllowJs.errors.txt @@ -1,16 +1,13 @@ DifferentNamesSpecifiedWithAllowJs/tsconfig.json(3,5): error TS6082: Only 'amd' and 'system' modules are supported alongside --out. -DifferentNamesSpecifiedWithAllowJs/tsconfig.json(4,5): error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. -==== DifferentNamesSpecifiedWithAllowJs/tsconfig.json (2 errors) ==== +==== DifferentNamesSpecifiedWithAllowJs/tsconfig.json (1 errors) ==== { "compilerOptions": { "out": "test.js", ~~~~~ !!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out. "allowJs": true - ~~~~~~~~~ -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. }, "files": [ "a.ts", "b.js" ] } diff --git a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/node/test.d.ts b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/node/test.d.ts index 4c0b8989316ef..bbae04a30bf94 100644 --- a/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/node/test.d.ts +++ b/tests/baselines/reference/project/jsFileCompilationDifferentNamesSpecifiedWithAllowJs/node/test.d.ts @@ -1 +1,2 @@ declare var test: number; +declare var test2: number; diff --git a/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/amd/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt b/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/amd/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt index aa7418ccc1420..45cdfd7a3bc42 100644 --- a/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/amd/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt +++ b/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/amd/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt @@ -1,14 +1,15 @@ +error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.d.ts' because it would overwrite input file. + Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.js' because it would overwrite input file. Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. -SameNameDTsNotSpecifiedWithAllowJs/tsconfig.json(1,24): error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. +!!! error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.d.ts' because it would overwrite input file. +!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. !!! error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.js' because it would overwrite input file. !!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. -==== SameNameDTsNotSpecifiedWithAllowJs/tsconfig.json (1 errors) ==== +==== SameNameDTsNotSpecifiedWithAllowJs/tsconfig.json (0 errors) ==== { "compilerOptions": { "allowJs": true } } - ~~~~~~~~~ -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. ==== SameNameDTsNotSpecifiedWithAllowJs/a.d.ts (0 errors) ==== declare var a: number; ==== SameNameDTsNotSpecifiedWithAllowJs/a.js (0 errors) ==== diff --git a/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/node/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt b/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/node/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt index aa7418ccc1420..45cdfd7a3bc42 100644 --- a/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/node/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt +++ b/tests/baselines/reference/project/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs/node/jsFileCompilationSameNameDtsNotSpecifiedWithAllowJs.errors.txt @@ -1,14 +1,15 @@ +error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.d.ts' because it would overwrite input file. + Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.js' because it would overwrite input file. Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. -SameNameDTsNotSpecifiedWithAllowJs/tsconfig.json(1,24): error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. +!!! error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.d.ts' because it would overwrite input file. +!!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. !!! error TS5055: Cannot write file 'SameNameDTsNotSpecifiedWithAllowJs/a.js' because it would overwrite input file. !!! error TS5055: Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig. -==== SameNameDTsNotSpecifiedWithAllowJs/tsconfig.json (1 errors) ==== +==== SameNameDTsNotSpecifiedWithAllowJs/tsconfig.json (0 errors) ==== { "compilerOptions": { "allowJs": true } } - ~~~~~~~~~ -!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'. ==== SameNameDTsNotSpecifiedWithAllowJs/a.d.ts (0 errors) ==== declare var a: number; ==== SameNameDTsNotSpecifiedWithAllowJs/a.js (0 errors) ==== diff --git a/tests/baselines/reference/reactImportDropped.types b/tests/baselines/reference/reactImportDropped.types index f3e8c3987af97..52d9ddfb13d2a 100644 --- a/tests/baselines/reference/reactImportDropped.types +++ b/tests/baselines/reference/reactImportDropped.types @@ -31,7 +31,7 @@ declare global { export default React.createClass({ >React.createClass({ render() { return ( null ); }}) : import("tests/cases/compiler/react").ClassicComponentClass >React.createClass : (spec: any) => import("tests/cases/compiler/react").ClassicComponentClass ->React : typeof React +>React : typeof import("tests/cases/compiler/react") >createClass : (spec: any) => import("tests/cases/compiler/react").ClassicComponentClass >{ render() { return ( null ); }} : { render(): any; } diff --git a/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.types b/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.types index 07eacfb8f4d9b..234782767b34f 100644 --- a/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.types +++ b/tests/baselines/reference/reactTransitiveImportHasValidDeclaration.types @@ -21,7 +21,7 @@ declare module 'react' { // augment } export interface StyledOtherComponentList { "div": React.DetailedHTMLProps, HTMLDivElement> ->"div" : import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement> +>"div" : import("tests/cases/compiler/node_modules/react/index").DetailedHTMLProps, HTMLDivElement> >React : any >React : any } @@ -36,24 +36,24 @@ import {StyledOtherComponent, StyledOtherComponentList} from "create-emotion-sty >StyledOtherComponentList : any export default function styled(tag: string): (o: object) => StyledOtherComponent<{}, StyledOtherComponentList["div"], any>; ->styled : (tag: string) => (o: object) => StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>styled : (tag: string) => (o: object) => StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index").DetailedHTMLProps, HTMLDivElement>, any> >tag : string >o : object === tests/cases/compiler/index.ts === import styled from "react-emotion" ->styled : (tag: string) => (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>styled : (tag: string) => (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index").DetailedHTMLProps, HTMLDivElement>, any> const Form = styled('div')({ color: "red" }) ->Form : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> ->styled('div')({ color: "red" }) : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> ->styled('div') : (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> ->styled : (tag: string) => (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>Form : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index").DetailedHTMLProps, HTMLDivElement>, any> +>styled('div')({ color: "red" }) : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index").DetailedHTMLProps, HTMLDivElement>, any> +>styled('div') : (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index").DetailedHTMLProps, HTMLDivElement>, any> +>styled : (tag: string) => (o: object) => import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index").DetailedHTMLProps, HTMLDivElement>, any> >'div' : "div" >{ color: "red" } : { color: string; } >color : string >"red" : "red" export default Form ->Form : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index.d.ts").DetailedHTMLProps, HTMLDivElement>, any> +>Form : import("tests/cases/compiler/node_modules/create-emotion-styled/index").StyledOtherComponent<{}, import("tests/cases/compiler/node_modules/react/index").DetailedHTMLProps, HTMLDivElement>, any> diff --git a/tests/baselines/reference/reexportClassDefinition.types b/tests/baselines/reference/reexportClassDefinition.types index c39bbf9c13695..c6d2a4a2f2f56 100644 --- a/tests/baselines/reference/reexportClassDefinition.types +++ b/tests/baselines/reference/reexportClassDefinition.types @@ -1,12 +1,12 @@ === tests/cases/conformance/externalModules/foo3.ts === import foo2 = require('./foo2') ->foo2 : { x: typeof x; } +>foo2 : { x: typeof import("tests/cases/conformance/externalModules/foo1"); } class x extends foo2.x {} >x : x ->foo2.x : x ->foo2 : { x: typeof x; } ->x : typeof x +>foo2.x : import("tests/cases/conformance/externalModules/foo1") +>foo2 : { x: typeof import("tests/cases/conformance/externalModules/foo1"); } +>x : typeof import("tests/cases/conformance/externalModules/foo1") === tests/cases/conformance/externalModules/foo1.ts === diff --git a/tests/baselines/reference/requireOfJsonFileTypes.js b/tests/baselines/reference/requireOfJsonFileTypes.js index e84f684187a10..31bd1f5b11e67 100644 --- a/tests/baselines/reference/requireOfJsonFileTypes.js +++ b/tests/baselines/reference/requireOfJsonFileTypes.js @@ -83,3 +83,27 @@ stringLiteral = d; numberLiteral = e; numberLiteral = f[0]; booleanLiteral = g[0]; + + +//// [out/b.d.ts] +export declare const a: boolean; +export declare const b: string; +export declare const c: null; +export declare const d: boolean; +//// [out/c.d.ts] +declare const _exports: (string | null)[]; +export = _exports; +//// [out/d.d.ts] +declare const _exports: string; +export = _exports; +//// [out/e.d.ts] +declare const _exports: number; +export = _exports; +//// [out/f.d.ts] +declare const _exports: number[]; +export = _exports; +//// [out/g.d.ts] +declare const _exports: boolean[]; +export = _exports; +//// [out/file1.d.ts] +export {}; diff --git a/tests/baselines/reference/requireOfJsonFileWithDeclaration.js b/tests/baselines/reference/requireOfJsonFileWithDeclaration.js index 2cb5085ffb7ff..cae409add9708 100644 --- a/tests/baselines/reference/requireOfJsonFileWithDeclaration.js +++ b/tests/baselines/reference/requireOfJsonFileWithDeclaration.js @@ -32,5 +32,8 @@ if (x) { } +//// [out/b.d.ts] +export declare const a: boolean; +export declare const b: string; //// [out/file1.d.ts] export {}; diff --git a/tests/baselines/reference/tsbuild/javascriptProjectEmit/incremental-declaration-doesnt-change/modifies-outfile-js-projects-and-concatenates-them-correctly.js b/tests/baselines/reference/tsbuild/javascriptProjectEmit/incremental-declaration-doesnt-change/modifies-outfile-js-projects-and-concatenates-them-correctly.js new file mode 100644 index 0000000000000..b863d923b661d --- /dev/null +++ b/tests/baselines/reference/tsbuild/javascriptProjectEmit/incremental-declaration-doesnt-change/modifies-outfile-js-projects-and-concatenates-them-correctly.js @@ -0,0 +1,254 @@ +//// [/lib/incremental-declaration-doesnt-changeOutput.txt] +/lib/tsc -b /src +exitCode:: 0 + + +//// [/src/sub-project/index.js] +/** + * @typedef {Nominal} MyNominal + */ +const c = /** @type {*} */(undefined); + + +//// [/src/sub-project/sub-project.d.ts] file written with same contents +//// [/src/sub-project/sub-project.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (undefined); + + +//// [/src/sub-project/sub-project.tsbuildinfo] +{ + "bundle": { + "commonSourceDirectory": "..", + "sourceFiles": [ + "./index.js" + ], + "js": { + "sections": [ + { + "pos": 0, + "end": 84, + "kind": "prepend", + "data": "../common/common.js", + "texts": [ + { + "pos": 0, + "end": 84, + "kind": "text" + } + ] + }, + { + "pos": 84, + "end": 187, + "kind": "text" + } + ] + }, + "dts": { + "sections": [ + { + "pos": 0, + "end": 64, + "kind": "prepend", + "data": "../common/common.d.ts", + "texts": [ + { + "pos": 0, + "end": 64, + "kind": "text" + } + ] + }, + { + "pos": 64, + "end": 220, + "kind": "text" + } + ] + } + }, + "version": "FakeTSVersion" +} + +//// [/src/sub-project/sub-project.tsbuildinfo.baseline.txt] +====================================================================== +File:: /src/sub-project/sub-project.js +---------------------------------------------------------------------- +prepend: (0-84):: ../common/common.js texts:: 1 +>>-------------------------------------------------------------------- +text: (0-84) +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + +---------------------------------------------------------------------- +text: (84-187) +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (undefined); + +====================================================================== +====================================================================== +File:: /src/sub-project/sub-project.d.ts +---------------------------------------------------------------------- +prepend: (0-64):: ../common/common.d.ts texts:: 1 +>>-------------------------------------------------------------------- +text: (0-64) +type Nominal = T & { + [Symbol.species]: Name; +}; + +---------------------------------------------------------------------- +text: (64-220) +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + +====================================================================== + +//// [/src/sub-project-2/sub-project-2.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (undefined); +var variable = { + key: /** @type {MyNominal} */ ('value') +}; +/** + * @return {keyof typeof variable} + */ +function getVar() { + return 'key'; +} + + +//// [/src/sub-project-2/sub-project-2.tsbuildinfo] +{ + "bundle": { + "commonSourceDirectory": "..", + "sourceFiles": [ + "./index.js" + ], + "js": { + "sections": [ + { + "pos": 0, + "end": 187, + "kind": "prepend", + "data": "../sub-project/sub-project.js", + "texts": [ + { + "pos": 0, + "end": 187, + "kind": "text" + } + ] + }, + { + "pos": 187, + "end": 343, + "kind": "text" + } + ] + }, + "dts": { + "sections": [ + { + "pos": 0, + "end": 220, + "kind": "prepend", + "data": "../sub-project/sub-project.d.ts", + "texts": [ + { + "pos": 0, + "end": 220, + "kind": "text" + } + ] + }, + { + "pos": 220, + "end": 361, + "kind": "text" + } + ] + } + }, + "version": "FakeTSVersion" +} + +//// [/src/sub-project-2/sub-project-2.tsbuildinfo.baseline.txt] +====================================================================== +File:: /src/sub-project-2/sub-project-2.js +---------------------------------------------------------------------- +prepend: (0-187):: ../sub-project/sub-project.js texts:: 1 +>>-------------------------------------------------------------------- +text: (0-187) +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (undefined); + +---------------------------------------------------------------------- +text: (187-343) +var variable = { + key: /** @type {MyNominal} */ ('value') +}; +/** + * @return {keyof typeof variable} + */ +function getVar() { + return 'key'; +} + +====================================================================== +====================================================================== +File:: /src/sub-project-2/sub-project-2.d.ts +---------------------------------------------------------------------- +prepend: (0-220):: ../sub-project/sub-project.d.ts texts:: 1 +>>-------------------------------------------------------------------- +text: (0-220) +type Nominal = T & { + [Symbol.species]: Name; +}; +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + +---------------------------------------------------------------------- +text: (220-361) +/** + * @return {keyof typeof variable} + */ +declare function getVar(): "key"; +declare namespace variable { + const key: MyNominal; +} + +====================================================================== + diff --git a/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-and-emits-them-correctly.js b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-and-emits-them-correctly.js new file mode 100644 index 0000000000000..2abc5b9119bde --- /dev/null +++ b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-and-emits-them-correctly.js @@ -0,0 +1,172 @@ +//// [/lib/common/nominal.d.ts] +export type Nominal = T & { + [Symbol.species]: Name; +}; + + +//// [/lib/common/nominal.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +module.exports = {}; + + +//// [/lib/common/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../lib.d.ts": { + "version": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n", + "signature": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n" + }, + "../../src/common/nominal.js": { + "version": "-9003723607-/**\n * @template T, Name\n * @typedef {T & {[Symbol.species]: Name}} Nominal\n */\nmodule.exports = {};\n", + "signature": "-15964609857-export type Nominal = T & {\r\n [Symbol.species]: Name;\r\n};\r\n" + } + }, + "options": { + "skipLibCheck": true, + "rootDir": "../../src", + "outDir": "..", + "allowJs": true, + "checkJs": true, + "declaration": true, + "composite": true, + "configFilePath": "../../src/common/tsconfig.json" + }, + "referencedMap": {}, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../src/common/nominal.js", + "../lib.d.ts" + ] + }, + "version": "FakeTSVersion" +} + +//// [/lib/initial-buildOutput.txt] +/lib/tsc -b /src +exitCode:: 0 + + +//// [/lib/sub-project/index.d.ts] +export type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + + +//// [/lib/sub-project/index.js] +"use strict"; +exports.__esModule = true; +/** + * @typedef {Nominal} MyNominal + */ + + +//// [/lib/sub-project/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../lib.d.ts": { + "version": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n", + "signature": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n" + }, + "../../src/common/nominal.js": { + "version": "-15964609857-export type Nominal = T & {\r\n [Symbol.species]: Name;\r\n};\r\n", + "signature": "-15964609857-export type Nominal = T & {\r\n [Symbol.species]: Name;\r\n};\r\n" + }, + "../../src/sub-project/index.js": { + "version": "-23375763082-import { Nominal } from '../common/nominal';\n\n/**\n * @typedef {Nominal} MyNominal\n */\n", + "signature": "-4500199036-export type MyNominal = string & {\r\n [Symbol.species]: \"MyNominal\";\r\n};\r\n" + } + }, + "options": { + "skipLibCheck": true, + "rootDir": "../../src", + "outDir": "..", + "allowJs": true, + "checkJs": true, + "declaration": true, + "composite": true, + "configFilePath": "../../src/sub-project/tsconfig.json" + }, + "referencedMap": { + "../../src/sub-project/index.js": [ + "../common/nominal.d.ts" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../src/common/nominal.js", + "../../src/sub-project/index.js", + "../lib.d.ts" + ] + }, + "version": "FakeTSVersion" +} + +//// [/lib/sub-project-2/index.d.ts] +/** + * @return {keyof typeof variable} + */ +export function getVar(): "key"; + + +//// [/lib/sub-project-2/index.js] +"use strict"; +exports.__esModule = true; +var variable = { + key: /** @type {MyNominal} */ ('value') +}; +/** + * @return {keyof typeof variable} + */ +function getVar() { + return 'key'; +} +exports.getVar = getVar; + + +//// [/lib/sub-project-2/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../lib.d.ts": { + "version": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n", + "signature": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n" + }, + "../../src/sub-project/index.js": { + "version": "-4500199036-export type MyNominal = string & {\r\n [Symbol.species]: \"MyNominal\";\r\n};\r\n", + "signature": "-4500199036-export type MyNominal = string & {\r\n [Symbol.species]: \"MyNominal\";\r\n};\r\n" + }, + "../../src/sub-project-2/index.js": { + "version": "9520601400-import { MyNominal } from '../sub-project/index';\n\nconst variable = {\n key: /** @type {MyNominal} */('value'),\n};\n\n/**\n * @return {keyof typeof variable}\n */\nexport function getVar() {\n return 'key';\n}\n", + "signature": "-9866665538-/**\r\n * @return {keyof typeof variable}\r\n */\r\nexport function getVar(): \"key\";\r\n" + } + }, + "options": { + "skipLibCheck": true, + "rootDir": "../../src", + "outDir": "..", + "allowJs": true, + "checkJs": true, + "declaration": true, + "composite": true, + "configFilePath": "../../src/sub-project-2/tsconfig.json" + }, + "referencedMap": { + "../../src/sub-project-2/index.js": [ + "../sub-project/index.d.ts" + ] + }, + "exportedModulesMap": {}, + "semanticDiagnosticsPerFile": [ + "../../src/sub-project-2/index.js", + "../../src/sub-project/index.js", + "../lib.d.ts" + ] + }, + "version": "FakeTSVersion" +} + diff --git a/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js new file mode 100644 index 0000000000000..42b4720340617 --- /dev/null +++ b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-js-based-projects-with-non-moved-json-files-and-emits-them-correctly.js @@ -0,0 +1,228 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc -b /src +exitCode:: 0 + + +//// [/out/sub-project/index.d.ts] +export const m: typeof mod; +import mod from "../common"; + + +//// [/out/sub-project/index.js] +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +exports.__esModule = true; +var common_1 = __importDefault(require("../common")); +exports.m = common_1["default"]; + + +//// [/out/sub-project/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n", + "signature": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n" + }, + "../../src/common/obj.json": { + "version": "-6323167306-export declare const val: number;\r\n", + "signature": "-6323167306-export declare const val: number;\r\n" + }, + "../../src/common/index.ts": { + "version": "-4085459678-import x = require(\"./obj.json\");\r\nexport = x;\r\n", + "signature": "-4085459678-import x = require(\"./obj.json\");\r\nexport = x;\r\n" + }, + "../../src/sub-project/index.js": { + "version": "-14684157955-import mod from '../common';\n\nexport const m = mod;\n", + "signature": "-229957289-export const m: typeof mod;\r\nimport mod from \"../common\";\r\n" + } + }, + "options": { + "skipLibCheck": true, + "rootDir": "../../src", + "outDir": "..", + "allowJs": true, + "checkJs": true, + "resolveJsonModule": true, + "esModuleInterop": true, + "declaration": true, + "composite": true, + "configFilePath": "../../src/sub-project/tsconfig.json" + }, + "referencedMap": { + "../../src/common/index.ts": [ + "../../src/common/obj.d.ts" + ], + "../../src/sub-project/index.js": [ + "../../src/common/index.d.ts" + ] + }, + "exportedModulesMap": { + "../../src/common/index.ts": [ + "../../src/common/obj.d.ts" + ] + }, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "../../src/common/index.ts", + "../../src/common/obj.json", + "../../src/sub-project/index.js" + ] + }, + "version": "FakeTSVersion" +} + +//// [/out/sub-project-2/index.d.ts] +export function getVar(): { + key: typeof import("../common/obj.json"); +}; + + +//// [/out/sub-project-2/index.js] +"use strict"; +exports.__esModule = true; +var index_1 = require("../sub-project/index"); +var variable = { + key: index_1.m +}; +function getVar() { + return variable; +} +exports.getVar = getVar; + + +//// [/out/sub-project-2/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n", + "signature": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n" + }, + "../../src/common/obj.json": { + "version": "-6323167306-export declare const val: number;\r\n", + "signature": "-6323167306-export declare const val: number;\r\n" + }, + "../../src/common/index.ts": { + "version": "-4085459678-import x = require(\"./obj.json\");\r\nexport = x;\r\n", + "signature": "-4085459678-import x = require(\"./obj.json\");\r\nexport = x;\r\n" + }, + "../../src/sub-project/index.js": { + "version": "-229957289-export const m: typeof mod;\r\nimport mod from \"../common\";\r\n", + "signature": "-229957289-export const m: typeof mod;\r\nimport mod from \"../common\";\r\n" + }, + "../../src/sub-project-2/index.js": { + "version": "13545386800-import { m } from '../sub-project/index';\n\nconst variable = {\n key: m,\n};\n\nexport function getVar() {\n return variable;\n}\n", + "signature": "-9206156860-export function getVar(): {\r\n key: typeof import(\"../common/obj.json\");\r\n};\r\n" + } + }, + "options": { + "skipLibCheck": true, + "rootDir": "../../src", + "outDir": "..", + "allowJs": true, + "checkJs": true, + "resolveJsonModule": true, + "esModuleInterop": true, + "declaration": true, + "composite": true, + "configFilePath": "../../src/sub-project-2/tsconfig.json" + }, + "referencedMap": { + "../../src/common/index.ts": [ + "../../src/common/obj.d.ts" + ], + "../../src/sub-project-2/index.js": [ + "../sub-project/index.d.ts" + ], + "../../src/sub-project/index.js": [ + "../../src/common/index.d.ts" + ] + }, + "exportedModulesMap": { + "../../src/common/index.ts": [ + "../../src/common/obj.d.ts" + ], + "../../src/sub-project-2/index.js": [ + "../../src/common/obj.d.ts" + ], + "../../src/sub-project/index.js": [ + "../../src/common/index.d.ts" + ] + }, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "../../src/common/index.ts", + "../../src/common/obj.json", + "../../src/sub-project-2/index.js", + "../../src/sub-project/index.js" + ] + }, + "version": "FakeTSVersion" +} + +//// [/src/common/index.d.ts] +import x = require("./obj.json"); +export = x; + + +//// [/src/common/index.js] +"use strict"; +var x = require("./obj.json"); +module.exports = x; + + +//// [/src/common/obj.d.ts] +export declare const val: number; + + +//// [/src/common/tsconfig.tsbuildinfo] +{ + "program": { + "fileInfos": { + "../../lib/lib.d.ts": { + "version": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n", + "signature": "-32082413277-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };\ninterface SymbolConstructor {\n readonly species: symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\n" + }, + "./obj.json": { + "version": "2151907832-{\n \"val\": 42\n}", + "signature": "-6323167306-export declare const val: number;\r\n" + }, + "./index.ts": { + "version": "-5032674136-import x = require(\"./obj.json\");\nexport = x;\n", + "signature": "-4085459678-import x = require(\"./obj.json\");\r\nexport = x;\r\n" + } + }, + "options": { + "skipLibCheck": true, + "rootDir": "..", + "outDir": "../..", + "allowJs": true, + "checkJs": true, + "resolveJsonModule": true, + "esModuleInterop": true, + "declaration": true, + "composite": true, + "configFilePath": "./tsconfig.json" + }, + "referencedMap": { + "./index.ts": [ + "./obj.json" + ] + }, + "exportedModulesMap": { + "./index.ts": [ + "./obj.json" + ] + }, + "semanticDiagnosticsPerFile": [ + "../../lib/lib.d.ts", + "./index.ts", + "./obj.json" + ] + }, + "version": "FakeTSVersion" +} + diff --git a/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-outfile-js-projects-and-concatenates-them-correctly.js b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-outfile-js-projects-and-concatenates-them-correctly.js new file mode 100644 index 0000000000000..c46f5e3baa1f9 --- /dev/null +++ b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/loads-outfile-js-projects-and-concatenates-them-correctly.js @@ -0,0 +1,342 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc -b /src +exitCode:: 0 + + +//// [/src/common/common.d.ts] +type Nominal = T & { + [Symbol.species]: Name; +}; + + +//// [/src/common/common.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + + +//// [/src/common/common.tsbuildinfo] +{ + "bundle": { + "commonSourceDirectory": "..", + "sourceFiles": [ + "./nominal.js" + ], + "js": { + "sections": [ + { + "pos": 0, + "end": 84, + "kind": "text" + } + ] + }, + "dts": { + "sections": [ + { + "pos": 0, + "end": 64, + "kind": "text" + } + ] + } + }, + "version": "FakeTSVersion" +} + +//// [/src/common/common.tsbuildinfo.baseline.txt] +====================================================================== +File:: /src/common/common.js +---------------------------------------------------------------------- +text: (0-84) +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + +====================================================================== +====================================================================== +File:: /src/common/common.d.ts +---------------------------------------------------------------------- +text: (0-64) +type Nominal = T & { + [Symbol.species]: Name; +}; + +====================================================================== + +//// [/src/sub-project/sub-project.d.ts] +type Nominal = T & { + [Symbol.species]: Name; +}; +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + + +//// [/src/sub-project/sub-project.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (null); + + +//// [/src/sub-project/sub-project.tsbuildinfo] +{ + "bundle": { + "commonSourceDirectory": "..", + "sourceFiles": [ + "./index.js" + ], + "js": { + "sections": [ + { + "pos": 0, + "end": 84, + "kind": "prepend", + "data": "../common/common.js", + "texts": [ + { + "pos": 0, + "end": 84, + "kind": "text" + } + ] + }, + { + "pos": 84, + "end": 182, + "kind": "text" + } + ] + }, + "dts": { + "sections": [ + { + "pos": 0, + "end": 64, + "kind": "prepend", + "data": "../common/common.d.ts", + "texts": [ + { + "pos": 0, + "end": 64, + "kind": "text" + } + ] + }, + { + "pos": 64, + "end": 220, + "kind": "text" + } + ] + } + }, + "version": "FakeTSVersion" +} + +//// [/src/sub-project/sub-project.tsbuildinfo.baseline.txt] +====================================================================== +File:: /src/sub-project/sub-project.js +---------------------------------------------------------------------- +prepend: (0-84):: ../common/common.js texts:: 1 +>>-------------------------------------------------------------------- +text: (0-84) +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + +---------------------------------------------------------------------- +text: (84-182) +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (null); + +====================================================================== +====================================================================== +File:: /src/sub-project/sub-project.d.ts +---------------------------------------------------------------------- +prepend: (0-64):: ../common/common.d.ts texts:: 1 +>>-------------------------------------------------------------------- +text: (0-64) +type Nominal = T & { + [Symbol.species]: Name; +}; + +---------------------------------------------------------------------- +text: (64-220) +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + +====================================================================== + +//// [/src/sub-project-2/sub-project-2.d.ts] +type Nominal = T & { + [Symbol.species]: Name; +}; +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; +/** + * @return {keyof typeof variable} + */ +declare function getVar(): "key"; +declare namespace variable { + const key: MyNominal; +} + + +//// [/src/sub-project-2/sub-project-2.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (null); +var variable = { + key: /** @type {MyNominal} */ ('value') +}; +/** + * @return {keyof typeof variable} + */ +function getVar() { + return 'key'; +} + + +//// [/src/sub-project-2/sub-project-2.tsbuildinfo] +{ + "bundle": { + "commonSourceDirectory": "..", + "sourceFiles": [ + "./index.js" + ], + "js": { + "sections": [ + { + "pos": 0, + "end": 182, + "kind": "prepend", + "data": "../sub-project/sub-project.js", + "texts": [ + { + "pos": 0, + "end": 182, + "kind": "text" + } + ] + }, + { + "pos": 182, + "end": 338, + "kind": "text" + } + ] + }, + "dts": { + "sections": [ + { + "pos": 0, + "end": 220, + "kind": "prepend", + "data": "../sub-project/sub-project.d.ts", + "texts": [ + { + "pos": 0, + "end": 220, + "kind": "text" + } + ] + }, + { + "pos": 220, + "end": 361, + "kind": "text" + } + ] + } + }, + "version": "FakeTSVersion" +} + +//// [/src/sub-project-2/sub-project-2.tsbuildinfo.baseline.txt] +====================================================================== +File:: /src/sub-project-2/sub-project-2.js +---------------------------------------------------------------------- +prepend: (0-182):: ../sub-project/sub-project.js texts:: 1 +>>-------------------------------------------------------------------- +text: (0-182) +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (null); + +---------------------------------------------------------------------- +text: (182-338) +var variable = { + key: /** @type {MyNominal} */ ('value') +}; +/** + * @return {keyof typeof variable} + */ +function getVar() { + return 'key'; +} + +====================================================================== +====================================================================== +File:: /src/sub-project-2/sub-project-2.d.ts +---------------------------------------------------------------------- +prepend: (0-220):: ../sub-project/sub-project.d.ts texts:: 1 +>>-------------------------------------------------------------------- +text: (0-220) +type Nominal = T & { + [Symbol.species]: Name; +}; +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + +---------------------------------------------------------------------- +text: (220-361) +/** + * @return {keyof typeof variable} + */ +declare function getVar(): "key"; +declare namespace variable { + const key: MyNominal; +} + +====================================================================== + diff --git a/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/modifies-outfile-js-projects-and-concatenates-them-correctly.js b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/modifies-outfile-js-projects-and-concatenates-them-correctly.js new file mode 100644 index 0000000000000..c46f5e3baa1f9 --- /dev/null +++ b/tests/baselines/reference/tsbuild/javascriptProjectEmit/initial-build/modifies-outfile-js-projects-and-concatenates-them-correctly.js @@ -0,0 +1,342 @@ +//// [/lib/initial-buildOutput.txt] +/lib/tsc -b /src +exitCode:: 0 + + +//// [/src/common/common.d.ts] +type Nominal = T & { + [Symbol.species]: Name; +}; + + +//// [/src/common/common.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + + +//// [/src/common/common.tsbuildinfo] +{ + "bundle": { + "commonSourceDirectory": "..", + "sourceFiles": [ + "./nominal.js" + ], + "js": { + "sections": [ + { + "pos": 0, + "end": 84, + "kind": "text" + } + ] + }, + "dts": { + "sections": [ + { + "pos": 0, + "end": 64, + "kind": "text" + } + ] + } + }, + "version": "FakeTSVersion" +} + +//// [/src/common/common.tsbuildinfo.baseline.txt] +====================================================================== +File:: /src/common/common.js +---------------------------------------------------------------------- +text: (0-84) +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + +====================================================================== +====================================================================== +File:: /src/common/common.d.ts +---------------------------------------------------------------------- +text: (0-64) +type Nominal = T & { + [Symbol.species]: Name; +}; + +====================================================================== + +//// [/src/sub-project/sub-project.d.ts] +type Nominal = T & { + [Symbol.species]: Name; +}; +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + + +//// [/src/sub-project/sub-project.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (null); + + +//// [/src/sub-project/sub-project.tsbuildinfo] +{ + "bundle": { + "commonSourceDirectory": "..", + "sourceFiles": [ + "./index.js" + ], + "js": { + "sections": [ + { + "pos": 0, + "end": 84, + "kind": "prepend", + "data": "../common/common.js", + "texts": [ + { + "pos": 0, + "end": 84, + "kind": "text" + } + ] + }, + { + "pos": 84, + "end": 182, + "kind": "text" + } + ] + }, + "dts": { + "sections": [ + { + "pos": 0, + "end": 64, + "kind": "prepend", + "data": "../common/common.d.ts", + "texts": [ + { + "pos": 0, + "end": 64, + "kind": "text" + } + ] + }, + { + "pos": 64, + "end": 220, + "kind": "text" + } + ] + } + }, + "version": "FakeTSVersion" +} + +//// [/src/sub-project/sub-project.tsbuildinfo.baseline.txt] +====================================================================== +File:: /src/sub-project/sub-project.js +---------------------------------------------------------------------- +prepend: (0-84):: ../common/common.js texts:: 1 +>>-------------------------------------------------------------------- +text: (0-84) +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ + +---------------------------------------------------------------------- +text: (84-182) +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (null); + +====================================================================== +====================================================================== +File:: /src/sub-project/sub-project.d.ts +---------------------------------------------------------------------- +prepend: (0-64):: ../common/common.d.ts texts:: 1 +>>-------------------------------------------------------------------- +text: (0-64) +type Nominal = T & { + [Symbol.species]: Name; +}; + +---------------------------------------------------------------------- +text: (64-220) +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + +====================================================================== + +//// [/src/sub-project-2/sub-project-2.d.ts] +type Nominal = T & { + [Symbol.species]: Name; +}; +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; +/** + * @return {keyof typeof variable} + */ +declare function getVar(): "key"; +declare namespace variable { + const key: MyNominal; +} + + +//// [/src/sub-project-2/sub-project-2.js] +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (null); +var variable = { + key: /** @type {MyNominal} */ ('value') +}; +/** + * @return {keyof typeof variable} + */ +function getVar() { + return 'key'; +} + + +//// [/src/sub-project-2/sub-project-2.tsbuildinfo] +{ + "bundle": { + "commonSourceDirectory": "..", + "sourceFiles": [ + "./index.js" + ], + "js": { + "sections": [ + { + "pos": 0, + "end": 182, + "kind": "prepend", + "data": "../sub-project/sub-project.js", + "texts": [ + { + "pos": 0, + "end": 182, + "kind": "text" + } + ] + }, + { + "pos": 182, + "end": 338, + "kind": "text" + } + ] + }, + "dts": { + "sections": [ + { + "pos": 0, + "end": 220, + "kind": "prepend", + "data": "../sub-project/sub-project.d.ts", + "texts": [ + { + "pos": 0, + "end": 220, + "kind": "text" + } + ] + }, + { + "pos": 220, + "end": 361, + "kind": "text" + } + ] + } + }, + "version": "FakeTSVersion" +} + +//// [/src/sub-project-2/sub-project-2.tsbuildinfo.baseline.txt] +====================================================================== +File:: /src/sub-project-2/sub-project-2.js +---------------------------------------------------------------------- +prepend: (0-182):: ../sub-project/sub-project.js texts:: 1 +>>-------------------------------------------------------------------- +text: (0-182) +/** + * @template T, Name + * @typedef {T & {[Symbol.species]: Name}} Nominal + */ +/** + * @typedef {Nominal} MyNominal + */ +var c = /** @type {*} */ (null); + +---------------------------------------------------------------------- +text: (182-338) +var variable = { + key: /** @type {MyNominal} */ ('value') +}; +/** + * @return {keyof typeof variable} + */ +function getVar() { + return 'key'; +} + +====================================================================== +====================================================================== +File:: /src/sub-project-2/sub-project-2.d.ts +---------------------------------------------------------------------- +prepend: (0-220):: ../sub-project/sub-project.d.ts texts:: 1 +>>-------------------------------------------------------------------- +text: (0-220) +type Nominal = T & { + [Symbol.species]: Name; +}; +/** + * @typedef {Nominal} MyNominal + */ +declare const c: any; +type MyNominal = string & { + [Symbol.species]: "MyNominal"; +}; + +---------------------------------------------------------------------- +text: (220-361) +/** + * @return {keyof typeof variable} + */ +declare function getVar(): "key"; +declare namespace variable { + const key: MyNominal; +} + +====================================================================== + diff --git a/tests/baselines/reference/typeFromPropertyAssignment17.types b/tests/baselines/reference/typeFromPropertyAssignment17.types index 8d32ac016b3ff..92577ce1da50b 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment17.types +++ b/tests/baselines/reference/typeFromPropertyAssignment17.types @@ -1,8 +1,8 @@ === tests/cases/conformance/salsa/use.js === /// var mini = require('./minimatch') ->mini : typeof minimatch ->require('./minimatch') : typeof minimatch +>mini : typeof import("tests/cases/conformance/salsa/minimatch") +>require('./minimatch') : typeof import("tests/cases/conformance/salsa/minimatch") >require : any >'./minimatch' : "./minimatch" @@ -10,7 +10,7 @@ mini.M.defaults() >mini.M.defaults() : any >mini.M.defaults : (def: any) => any >mini.M : typeof M ->mini : typeof minimatch +>mini : typeof import("tests/cases/conformance/salsa/minimatch") >M : typeof M >defaults : (def: any) => any @@ -18,7 +18,7 @@ var m = new mini.M() >m : M >new mini.M() : M >mini.M : typeof M ->mini : typeof minimatch +>mini : typeof import("tests/cases/conformance/salsa/minimatch") >M : typeof M m.m() @@ -30,7 +30,7 @@ m.m() mini.filter() >mini.filter() : void >mini.filter : () => void ->mini : typeof minimatch +>mini : typeof import("tests/cases/conformance/salsa/minimatch") >filter : () => void === tests/cases/conformance/salsa/types.d.ts === diff --git a/tests/baselines/reference/typeFromPropertyAssignment19.types b/tests/baselines/reference/typeFromPropertyAssignment19.types index 87c76be3099ea..2f5f0e87ad324 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment19.types +++ b/tests/baselines/reference/typeFromPropertyAssignment19.types @@ -1,8 +1,8 @@ === tests/cases/conformance/salsa/index.js === /// const C = require("./semver") ->C : typeof C ->require("./semver") : typeof C +>C : typeof import("tests/cases/conformance/salsa/semver") +>require("./semver") : typeof import("tests/cases/conformance/salsa/semver") >require : any >"./semver" : "./semver" @@ -10,7 +10,7 @@ var two = C.f(1) >two : any >C.f(1) : any >C.f : (n: any) => any ->C : typeof C +>C : typeof import("tests/cases/conformance/salsa/semver") >f : (n: any) => any >1 : 1 diff --git a/tests/baselines/reference/typedefCrossModule2.types b/tests/baselines/reference/typedefCrossModule2.types index 419a176227d4a..00310fe009928 100644 --- a/tests/baselines/reference/typedefCrossModule2.types +++ b/tests/baselines/reference/typedefCrossModule2.types @@ -1,7 +1,7 @@ === tests/cases/conformance/jsdoc/use.js === var mod = require('./mod1.js'); ->mod : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } ->require('./mod1.js') : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } +>mod : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } +>require('./mod1.js') : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } >require : any >'./mod1.js' : "./mod1.js" @@ -17,7 +17,7 @@ var bbb = new mod.Baz(); >bbb : any >new mod.Baz() : any >mod.Baz : any ->mod : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } +>mod : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } >Baz : any === tests/cases/conformance/jsdoc/mod1.js === @@ -31,16 +31,16 @@ class Foo { } // should error exports.Bar = class { } >exports.Bar = class { } : typeof Bar >exports.Bar : typeof Bar ->exports : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } +>exports : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } >Bar : typeof Bar >class { } : typeof Bar /** @typedef {number} Baz */ module.exports = { ->module.exports = { Baz: class { }} : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } ->module.exports : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } ->module : { "tests/cases/conformance/jsdoc/mod1": { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; }; } ->exports : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } +>module.exports = { Baz: class { }} : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } +>module.exports : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } +>module : { "tests/cases/conformance/jsdoc/mod1": { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; }; } +>exports : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } >{ Baz: class { }} : { Baz: typeof Baz; } Baz: class { } @@ -58,17 +58,17 @@ var Qux = 2; /** @typedef {number} Quid */ exports.Quid = 2; >exports.Quid = 2 : 2 ->exports.Quid : any ->exports : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } ->Quid : any +>exports.Quid : number +>exports : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } +>Quid : number >2 : 2 /** @typedef {number} Quack */ module.exports = { ->module.exports = { Quack: 2} : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } ->module.exports : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } ->module : { "tests/cases/conformance/jsdoc/mod1": { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; }; } ->exports : { Baz: any; Bar: typeof Bar; Quid: any; } | { Quack: any; Bar: typeof Bar; Quid: any; } +>module.exports = { Quack: 2} : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } +>module.exports : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } +>module : { "tests/cases/conformance/jsdoc/mod1": { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; }; } +>exports : { Baz: any; Bar: typeof Bar; Quid: number; } | { Quack: any; Bar: typeof Bar; Quid: number; } >{ Quack: 2} : { Quack: number; } Quack: 2 diff --git a/tests/baselines/reference/umd-augmentation-2.symbols b/tests/baselines/reference/umd-augmentation-2.symbols index d24f1367f83f2..ee138add1996a 100644 --- a/tests/baselines/reference/umd-augmentation-2.symbols +++ b/tests/baselines/reference/umd-augmentation-2.symbols @@ -3,9 +3,9 @@ /// let v = new Math2d.Vector(3, 2); >v : Symbol(v, Decl(a.ts, 2, 3)) ->Math2d.Vector : Symbol(Vector, Decl(index.d.ts, 5, 1), Decl(math2d-augment.d.ts, 2, 25)) +>Math2d.Vector : Symbol(Math2d.Vector, Decl(index.d.ts, 5, 1), Decl(math2d-augment.d.ts, 2, 25)) >Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0)) ->Vector : Symbol(Vector, Decl(index.d.ts, 5, 1), Decl(math2d-augment.d.ts, 2, 25)) +>Vector : Symbol(Math2d.Vector, Decl(index.d.ts, 5, 1), Decl(math2d-augment.d.ts, 2, 25)) let magnitude = Math2d.getLength(v); >magnitude : Symbol(magnitude, Decl(a.ts, 3, 3)) @@ -18,15 +18,15 @@ let p: Math2d.Point = v.translate(5, 5); >p : Symbol(p, Decl(a.ts, 4, 3)) >Math2d : Symbol(Math2d, Decl(index.d.ts, 0, 0)) >Point : Symbol(Math2d.Point, Decl(index.d.ts, 0, 27)) ->v.translate : Symbol(Vector.translate, Decl(index.d.ts, 10, 35)) +>v.translate : Symbol(Math2d.Vector.translate, Decl(index.d.ts, 10, 35)) >v : Symbol(v, Decl(a.ts, 2, 3)) ->translate : Symbol(Vector.translate, Decl(index.d.ts, 10, 35)) +>translate : Symbol(Math2d.Vector.translate, Decl(index.d.ts, 10, 35)) p = v.reverse(); >p : Symbol(p, Decl(a.ts, 4, 3)) ->v.reverse : Symbol(Vector.reverse, Decl(math2d-augment.d.ts, 4, 19)) +>v.reverse : Symbol(Math2d.Vector.reverse, Decl(math2d-augment.d.ts, 4, 19)) >v : Symbol(v, Decl(a.ts, 2, 3)) ->reverse : Symbol(Vector.reverse, Decl(math2d-augment.d.ts, 4, 19)) +>reverse : Symbol(Math2d.Vector.reverse, Decl(math2d-augment.d.ts, 4, 19)) var t = p.x; >t : Symbol(t, Decl(a.ts, 6, 3)) diff --git a/tests/baselines/reference/umd-augmentation-2.types b/tests/baselines/reference/umd-augmentation-2.types index 45b4f7f855d08..f5806f71d96fb 100644 --- a/tests/baselines/reference/umd-augmentation-2.types +++ b/tests/baselines/reference/umd-augmentation-2.types @@ -2,29 +2,29 @@ /// /// let v = new Math2d.Vector(3, 2); ->v : import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector ->new Math2d.Vector(3, 2) : import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector ->Math2d.Vector : typeof import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector +>v : Math2d.Vector +>new Math2d.Vector(3, 2) : Math2d.Vector +>Math2d.Vector : typeof Math2d.Vector >Math2d : typeof Math2d ->Vector : typeof import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector +>Vector : typeof Math2d.Vector >3 : 3 >2 : 2 let magnitude = Math2d.getLength(v); >magnitude : number >Math2d.getLength(v) : number ->Math2d.getLength : (p: import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector) => number +>Math2d.getLength : (p: Math2d.Vector) => number >Math2d : typeof Math2d ->getLength : (p: import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector) => number ->v : import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector +>getLength : (p: Math2d.Vector) => number +>v : Math2d.Vector let p: Math2d.Point = v.translate(5, 5); >p : Math2d.Point >Math2d : any ->v.translate(5, 5) : import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector ->v.translate : (dx: number, dy: number) => import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector ->v : import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector ->translate : (dx: number, dy: number) => import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector +>v.translate(5, 5) : Math2d.Vector +>v.translate : (dx: number, dy: number) => Math2d.Vector +>v : Math2d.Vector +>translate : (dx: number, dy: number) => Math2d.Vector >5 : 5 >5 : 5 @@ -33,7 +33,7 @@ p = v.reverse(); >p : Math2d.Point >v.reverse() : Math2d.Point >v.reverse : () => Math2d.Point ->v : import("tests/cases/conformance/externalModules/node_modules/math2d/index").Vector +>v : Math2d.Vector >reverse : () => Math2d.Point var t = p.x; diff --git a/tests/baselines/reference/umd-augmentation-3.types b/tests/baselines/reference/umd-augmentation-3.types index 18162921124c4..2c0f2dca8960c 100644 --- a/tests/baselines/reference/umd-augmentation-3.types +++ b/tests/baselines/reference/umd-augmentation-3.types @@ -49,7 +49,7 @@ export as namespace Math2d; >Math2d : typeof import("tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts") export = M2D; ->M2D : typeof M2D +>M2D : typeof import("tests/cases/conformance/externalModules/node_modules/math2d/index") declare namespace M2D { >M2D : typeof import("tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts") diff --git a/tests/baselines/reference/umd-augmentation-4.types b/tests/baselines/reference/umd-augmentation-4.types index bb68c080d2ee0..94c8fa957f31f 100644 --- a/tests/baselines/reference/umd-augmentation-4.types +++ b/tests/baselines/reference/umd-augmentation-4.types @@ -47,7 +47,7 @@ export as namespace Math2d; >Math2d : typeof import("tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts") export = M2D; ->M2D : typeof M2D +>M2D : typeof import("tests/cases/conformance/externalModules/node_modules/math2d/index") declare namespace M2D { >M2D : typeof import("tests/cases/conformance/externalModules/node_modules/math2d/index.d.ts") diff --git a/tests/baselines/reference/umd9.types b/tests/baselines/reference/umd9.types index e4fc9376efdad..d62eafb475447 100644 --- a/tests/baselines/reference/umd9.types +++ b/tests/baselines/reference/umd9.types @@ -1,8 +1,8 @@ === tests/cases/conformance/externalModules/a.ts === /// export const x = Foo; // OK in value position because allowUmdGlobalAccess: true ->x : typeof Thing ->Foo : typeof Thing +>x : typeof import("tests/cases/conformance/externalModules/foo") +>Foo : typeof import("tests/cases/conformance/externalModules/foo") === tests/cases/conformance/externalModules/foo.d.ts === declare class Thing { diff --git a/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.types b/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.types index 2c0ce91aec8d5..1f5373f82c806 100644 --- a/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.types +++ b/tests/baselines/reference/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.types @@ -10,10 +10,10 @@ export { }; === tests/cases/compiler/module.d.ts === export = React; ->React : typeof React +>React : typeof import("tests/cases/compiler/module") export as namespace React; ->React : typeof React +>React : typeof import("tests/cases/compiler/module") declare namespace React { >React : typeof React diff --git a/tests/cases/compiler/declarationFileNoCrashOnExtraExportModifier.ts b/tests/cases/compiler/declarationFileNoCrashOnExtraExportModifier.ts new file mode 100644 index 0000000000000..2bd193dfca6dd --- /dev/null +++ b/tests/cases/compiler/declarationFileNoCrashOnExtraExportModifier.ts @@ -0,0 +1,14 @@ +// @filename: input.ts +export = exports; +declare class exports { + constructor(p: number); + t: number; +} +export class Sub { + instance!: { + t: number; + }; +} +declare namespace exports { + export { Sub }; +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationImportTypeAliasInferredAndEmittable.ts b/tests/cases/compiler/declarationImportTypeAliasInferredAndEmittable.ts new file mode 100644 index 0000000000000..a63ae7f75ddd0 --- /dev/null +++ b/tests/cases/compiler/declarationImportTypeAliasInferredAndEmittable.ts @@ -0,0 +1,19 @@ +// @declaration: true +// @filename: foo.ts +class Conn { + constructor() { } + item = 3; + method() { } +} + +export = Conn; +// @filename: usage.ts +type Conn = import("./foo"); +declare var x: Conn; + +export class Wrap { + connItem: number; + constructor(c = x) { + this.connItem = c.item; + } +} diff --git a/tests/cases/compiler/jsFileCompilationDuplicateVariable.ts b/tests/cases/compiler/jsFileCompilationDuplicateVariable.ts index cf2e27de885e5..b100fc748c83d 100644 --- a/tests/cases/compiler/jsFileCompilationDuplicateVariable.ts +++ b/tests/cases/compiler/jsFileCompilationDuplicateVariable.ts @@ -5,4 +5,4 @@ var x = 10; // @filename: b.js -var x = "hello"; // No error is recorded here and declaration file will show this as number \ No newline at end of file +var x = "hello"; // Error is recorded here, but suppressed because the js file isn't checked \ No newline at end of file diff --git a/tests/cases/compiler/jsFileCompilationDuplicateVariableErrorReported.ts b/tests/cases/compiler/jsFileCompilationDuplicateVariableErrorReported.ts index 05b750fe6082b..11b7711eb0eff 100644 --- a/tests/cases/compiler/jsFileCompilationDuplicateVariableErrorReported.ts +++ b/tests/cases/compiler/jsFileCompilationDuplicateVariableErrorReported.ts @@ -5,4 +5,4 @@ var x = "hello"; // @filename: a.ts -var x = 10; // Error reported so no declaration file generated? \ No newline at end of file +var x = 10; // Error reported \ No newline at end of file diff --git a/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.ts b/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.ts index 1741e3c280270..347c501c88ef5 100644 --- a/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.ts +++ b/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithNoOut.ts @@ -6,7 +6,7 @@ class c { // @filename: b.ts /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files +// b.d.ts should have c.d.ts as the reference path function foo() { } diff --git a/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.ts b/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.ts index 35228678bb72a..d2173ba28ef8c 100644 --- a/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.ts +++ b/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOut.ts @@ -7,7 +7,6 @@ class c { // @filename: b.ts /// -// error on above reference when emitting declarations function foo() { } diff --git a/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.ts b/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.ts index 64e009c251591..39cead024e599 100644 --- a/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.ts +++ b/tests/cases/compiler/jsFileCompilationErrorOnDeclarationsWithJsFileReferenceWithOutDir.ts @@ -7,7 +7,6 @@ class c { // @filename: b.ts /// -// b.d.ts should have c.js as the reference path since we dont emit declarations for js files function foo() { } diff --git a/tests/cases/compiler/namespacesWithTypeAliasOnlyExportsMerge.ts b/tests/cases/compiler/namespacesWithTypeAliasOnlyExportsMerge.ts new file mode 100644 index 0000000000000..30e02a20dfa21 --- /dev/null +++ b/tests/cases/compiler/namespacesWithTypeAliasOnlyExportsMerge.ts @@ -0,0 +1,44 @@ +// @filename: constAndNS.ts +type A = number; +declare const Q: number; +declare namespace Q { + export { A }; +} +declare const try1: Q.A; +declare namespace Q2 { + export { Q } +} +declare const try2: Q2.Q.A; +declare namespace Q3 { + export {A as B}; +} +declare const try3: Q3.B; +declare namespace Q4 { + export { Q as default }; +} +declare const try4: Q4.default.A; +export {}; +// @filename: circular.ts +declare namespace NS1 { + export { NS2 }; +} +declare namespace NS2 { + export { NS1 }; +} +export {}; +// @filename: circularWithUses.ts +type A = string; +type B = number; +declare namespace NS1 { + export { NS2, A }; +} +declare namespace NS2 { + export { NS1, B }; +} +export {}; +declare const try1: NS1.A; +declare const try2: NS2.B; +declare const try3: NS1.NS2.B; +declare const try4: NS2.NS1.A; +declare const try5: NS1.NS2.NS1.A; +declare const try6: NS2.NS1.NS2.B; diff --git a/tests/cases/compiler/noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts b/tests/cases/compiler/noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts new file mode 100644 index 0000000000000..12f6c3dacfa96 --- /dev/null +++ b/tests/cases/compiler/noCircularDefinitionOnExportOfPrivateInMergedNamespace.ts @@ -0,0 +1,6 @@ +const cat = 12; +class Foo {} +export = Foo; +declare namespace Foo { + export { cat }; +} \ No newline at end of file diff --git a/tests/cases/compiler/requireOfJsonFileTypes.ts b/tests/cases/compiler/requireOfJsonFileTypes.ts index ce2aed2e824f2..5681c071cf681 100644 --- a/tests/cases/compiler/requireOfJsonFileTypes.ts +++ b/tests/cases/compiler/requireOfJsonFileTypes.ts @@ -4,6 +4,7 @@ // @strictNullChecks: true // @fullEmitPaths: true // @resolveJsonModule: true +// @declaration: true // @Filename: file1.ts import b = require('./b.json'); diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassExtendsVisibility.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassExtendsVisibility.ts new file mode 100644 index 0000000000000..300791253669f --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassExtendsVisibility.ts @@ -0,0 +1,17 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: bar.js +class Bar {} +module.exports = Bar; +// @filename: cls.js +const Bar = require("./bar"); +const Strings = { + a: "A", + b: "B" +}; +class Foo extends Bar {} +module.exports = Foo; +module.exports.Strings = Strings; \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClasses.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClasses.ts new file mode 100644 index 0000000000000..c97f8f5d9001b --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClasses.ts @@ -0,0 +1,199 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js +export class A {} + +export class B { + static cat = "cat"; +} + +export class C { + static Cls = class {} +} + +export class D { + /** + * @param {number} a + * @param {number} b + */ + constructor(a, b) {} +} + +/** + * @template T,U + */ +export class E { + /** + * @type {T & U} + */ + field; + + // @readonly is currently unsupported, it seems - included here just in case that changes + /** + * @type {T & U} + * @readonly + */ + readonlyField; + + initializedField = 12; + + /** + * @return {U} + */ + get f1() { return /** @type {*} */(null); } + + /** + * @param {U} _p + */ + set f1(_p) {} + + /** + * @return {U} + */ + get f2() { return /** @type {*} */(null); } + + /** + * @param {U} _p + */ + set f3(_p) {} + + /** + * @param {T} a + * @param {U} b + */ + constructor(a, b) {} + + + /** + * @type {string} + */ + static staticField; + + // @readonly is currently unsupported, it seems - included here just in case that changes + /** + * @type {string} + * @readonly + */ + static staticReadonlyField; + + static staticInitializedField = 12; + + /** + * @return {string} + */ + static get s1() { return ""; } + + /** + * @param {string} _p + */ + static set s1(_p) {} + + /** + * @return {string} + */ + static get s2() { return ""; } + + /** + * @param {string} _p + */ + static set s3(_p) {} +} + +/** + * @template T,U + */ +export class F { + /** + * @type {T & U} + */ + field; + /** + * @param {T} a + * @param {U} b + */ + constructor(a, b) {} + + /** + * @template A,B + * @param {A} a + * @param {B} b + */ + static create(a, b) { return new F(a, b); } +} + +class G {} + +export { G }; + +class HH {} + +export { HH as H }; + +export class I {} +export { I as II }; + +export { J as JJ }; +export class J {} + + +export class K { + constructor() { + this.p1 = 12; + this.p2 = "ok"; + } + + method() { + return this.p1; + } +} + +export class L extends K {} + +export class M extends null { + constructor() { + this.prop = 12; + } +} + + +/** + * @template T + */ +export class N extends L { + /** + * @param {T} param + */ + constructor(param) { + super(); + this.another = param; + } +} + +/** + * @template U + * @extends {N} + */ +export class O extends N { + /** + * @param {U} param + */ + constructor(param) { + super(param); + this.another2 = param; + } +} + +var x = /** @type {*} */(null); + +export class VariableBase extends x {} + +export class HasStatics { + static staticMethod() {} +} + +export class ExtendsStatics extends HasStatics { + static also() {} +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassesErr.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassesErr.ts new file mode 100644 index 0000000000000..d627fa8236bd7 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsClassesErr.ts @@ -0,0 +1,76 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js + +// Pretty much all of this should be an error, (since index signatures and generics are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export class M { + field: T; +} + +export class N extends M { + other: U; +} + +export class O { + [idx: string]: string; +} + +export class P extends O {} + +export class Q extends O { + [idx: string]: "ok"; +} + +export class R extends O { + [idx: number]: "ok"; +} + +export class S extends O { + [idx: string]: "ok"; + [idx: number]: never; +} + +export class T { + [idx: number]: string; +} + +export class U extends T {} + + +export class V extends T { + [idx: string]: string; +} + +export class W extends T { + [idx: number]: "ok"; +} + +export class X extends T { + [idx: string]: string; + [idx: number]: "ok"; +} + +export class Y { + [idx: string]: {x: number}; + [idx: number]: {x: number, y: number}; +} + +export class Z extends Y {} + +export class AA extends Y { + [idx: string]: {x: number, y: number}; +} + +export class BB extends Y { + [idx: number]: {x: 0, y: 0}; +} + +export class CC extends Y { + [idx: string]: {x: number, y: number}; + [idx: number]: {x: 0, y: 0}; +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsComputedNames.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsComputedNames.ts new file mode 100644 index 0000000000000..6a44652ac54a8 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsComputedNames.ts @@ -0,0 +1,32 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @lib: es6 +// @outDir: ./out +// @declaration: true +// @filename: index.js +const TopLevelSym = Symbol(); +const InnerSym = Symbol(); +module.exports = { + [TopLevelSym](x = 12) { + return x; + }, + items: { + [InnerSym]: (arg = {x: 12}) => arg.x + } +} + +// @filename: index2.js +const TopLevelSym = Symbol(); +const InnerSym = Symbol(); + +export class MyClass { + static [TopLevelSym] = 12; + [InnerSym] = "ok"; + /** + * @param {typeof TopLevelSym | typeof InnerSym} _p + */ + constructor(_p = InnerSym) { + // switch on _p + } +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault.ts new file mode 100644 index 0000000000000..35543033b7a4e --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefault.ts @@ -0,0 +1,42 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index1.js +export default 12; + +// @filename: index2.js +export default function foo() { + return foo; +} +export const x = foo; +export { foo as bar }; + +// @filename: index3.js +export default class Foo { + a = /** @type {Foo} */(null); +}; +export const X = Foo; +export { Foo as Bar }; + +// @filename: index4.js +import Fab from "./index3"; +class Bar extends Fab { + x = /** @type {Bar} */(null); +} +export default Bar; + +// @filename: index5.js +// merge type alias and const (OK) +export default 12; +/** + * @typedef {string | number} default + */ + +// @filename: index6.js +// merge type alias and function (OK) +export default function func() {}; +/** + * @typedef {string | number} default + */ diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefaultsErr.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefaultsErr.ts new file mode 100644 index 0000000000000..13134c33cddcc --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsDefaultsErr.ts @@ -0,0 +1,30 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index1.js +// merge type alias and alias (should error, see #32367) +class Cls { + x = 12; + static y = "ok" +} +export default Cls; +/** + * @typedef {string | number} default + */ + +// @filename: index2.js +// merge type alias and class (error message improvement needed, see #32368) +export default class C {}; +/** + * @typedef {string | number} default + */ + +// @filename: index3.js +// merge type alias and variable (behavior is borked, see #32366) +const x = 12; +export {x as default}; +/** + * @typedef {string | number} default + */ diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsEnumTag.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsEnumTag.ts new file mode 100644 index 0000000000000..fb4749e50868b --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsEnumTag.ts @@ -0,0 +1,53 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js +/** @enum {string} */ +export const Target = { + START: "start", + MIDDLE: "middle", + END: "end", + /** @type {number} */ + OK_I_GUESS: 2 +} +/** @enum number */ +export const Second = { + OK: 1, + /** @type {number} */ + FINE: 2, +} +/** @enum {function(number): number} */ +export const Fs = { + ADD1: n => n + 1, + ID: n => n, + SUB1: n => n - 1 +} + +/** + * @param {Target} t + * @param {Second} s + * @param {Fs} f + */ +export function consume(t,s,f) { + /** @type {string} */ + var str = t + /** @type {number} */ + var num = s + /** @type {(n: number) => number} */ + var fun = f + /** @type {Target} */ + var v = Target.START + v = 'something else' // allowed, like Typescript's classic enums and unlike its string enums +} +/** @param {string} s */ +export function ff(s) { + // element access with arbitrary string is an error only with noImplicitAny + if (!Target[s]) { + return null + } + else { + return Target[s] + } +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsEnums.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsEnums.ts new file mode 100644 index 0000000000000..e0300a4ddc43b --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsEnums.ts @@ -0,0 +1,68 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js + +// Pretty much all of this should be an error, (since enums are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export enum A {} + +export enum B { + Member +} + +enum C {} + +export { C }; + +enum DD {} + +export { DD as D }; + +export enum E {} +export { E as EE }; + +export { F as FF }; +export enum F {} + +export enum G { + A = 1, + B, + C +} + +export enum H { + A = "a", + B = "b" +} + +export enum I { + A = "a", + B = 0, + C +} + +export const enum J { + A = 1, + B, + C +} + +export enum K { + None = 0, + A = 1 << 0, + B = 1 << 1, + C = 1 << 2, + Mask = A | B | C, +} + +export const enum L { + None = 0, + A = 1 << 0, + B = 1 << 1, + C = 1 << 2, + Mask = A | B | C, +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpression.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpression.ts new file mode 100644 index 0000000000000..cdbe1c37dbf0b --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpression.ts @@ -0,0 +1,14 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js +module.exports = class Thing { + /** + * @param {number} p + */ + constructor(p) { + this.t = 12 + p; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionAnonymous.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionAnonymous.ts new file mode 100644 index 0000000000000..339de116c6566 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionAnonymous.ts @@ -0,0 +1,14 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js +module.exports = class { + /** + * @param {number} p + */ + constructor(p) { + this.t = 12 + p; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.ts new file mode 100644 index 0000000000000..0caa95933d3b7 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub.ts @@ -0,0 +1,19 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js +module.exports = class { + /** + * @param {number} p + */ + constructor(p) { + this.t = 12 + p; + } +} +module.exports.Sub = class { + constructor() { + this.instance = new module.exports(10); + } +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionShadowing.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionShadowing.ts new file mode 100644 index 0000000000000..847632ca970cd --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedClassExpressionShadowing.ts @@ -0,0 +1,19 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js +// TODO: Fixup +class A { + member = new Q(); +} +class Q { + x = 42; +} +module.exports = class Q { + constructor() { + this.x = new A(); + } +} +module.exports.Another = Q; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedVisibility.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedVisibility.ts new file mode 100644 index 0000000000000..23bbed1af2852 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignedVisibility.ts @@ -0,0 +1,21 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: obj.js +module.exports = class Obj { + constructor() { + this.x = 12; + } +} +// @filename: index.js +const Obj = require("./obj"); + +class Container { + constructor() { + this.usage = new Obj(); + } +} + +module.exports = Container; \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignmentExpressionPlusSecondary.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignmentExpressionPlusSecondary.ts new file mode 100644 index 0000000000000..cf4bf91320aad --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignmentExpressionPlusSecondary.ts @@ -0,0 +1,18 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js +const Strings = { + a: "A", + b: "B" +}; +module.exports = { + thing: "ok", + also: "ok", + desc: { + item: "ok" + } +}; +module.exports.Strings = Strings; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignmentWithKeywordName.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignmentWithKeywordName.ts new file mode 100644 index 0000000000000..0dc741ed83c5b --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportAssignmentWithKeywordName.ts @@ -0,0 +1,14 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js +var x = 12; +module.exports = { + extends: 'base', + more: { + others: ['strs'] + }, + x +}; \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDefinePropertyEmit.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDefinePropertyEmit.ts new file mode 100644 index 0000000000000..419e0146e9faf --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportDefinePropertyEmit.ts @@ -0,0 +1,63 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @declaration: true +// @filename: index.js +Object.defineProperty(module.exports, "a", { value: function a() {} }); + +Object.defineProperty(module.exports, "b", { value: function b() {} }); +Object.defineProperty(module.exports.b, "cat", { value: "cat" }); + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +function d(a, b) { return /** @type {*} */(null); } +Object.defineProperty(module.exports, "d", { value: d }); + + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +function e(a, b) { return /** @type {*} */(null); } +Object.defineProperty(module.exports, "e", { value: e }); + +/** + * @template T + * @param {T} a + */ +function f(a) { + return a; +} +Object.defineProperty(module.exports, "f", { value: f }); +Object.defineProperty(module.exports.f, "self", { value: module.exports.f }); + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { + return a.x && b.y(); +} +Object.defineProperty(module.exports, "g", { value: g }); + + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} +Object.defineProperty(module.exports, "h", { value: hh }); + +Object.defineProperty(module.exports, "i", { value: function i(){} }); +Object.defineProperty(module.exports, "ii", { value: module.exports.i }); + +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +Object.defineProperty(module.exports, "jj", { value: module.exports.j }); +Object.defineProperty(module.exports, "j", { value: function j() {} }); diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportForms.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportForms.ts new file mode 100644 index 0000000000000..5a512c9c9833f --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportForms.ts @@ -0,0 +1,61 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: cls.js +export class Foo {} + +// @filename: func.js +export function func() {} + +// @filename: bar.js +export * from "./cls"; + +// @filename: bar2.js +export * from "./func"; +export * from "./cls"; + +// @filename: baz.js +import {Foo} from "./cls"; +export {Foo}; + +// @filename: bat.js +import * as ns from "./cls"; +export default ns; + +// @filename: ban.js +import * as ns from "./cls"; +export {ns}; + +// @filename: bol.js +import * as ns from "./cls"; +export { ns as classContainer }; + +// @filename: cjs.js +const ns = require("./cls"); +module.exports = { ns }; + +// @filename: cjs2.js +const ns = require("./cls"); +module.exports = ns; + +// @filename: cjs3.js +const ns = require("./cls"); +module.exports.ns = ns; + +// @filename: cjs4.js +const ns = require("./cls"); +module.exports.names = ns; + +// @filename: includeAll.js +import "./cjs4"; +import "./cjs3"; +import "./cjs2"; +import "./cjs"; +import "./bol"; +import "./ban"; +import "./bat"; +import "./baz"; +import "./bar"; +import "./bar2"; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportFormsErr.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportFormsErr.ts new file mode 100644 index 0000000000000..4360f9a90f368 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportFormsErr.ts @@ -0,0 +1,24 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: cls.js +export class Foo {} + +// @filename: bar.js +import ns = require("./cls"); +export = ns; // TS Only + +// @filename: bin.js +import * as ns from "./cls"; +module.exports = ns; // We refuse to bind cjs module exports assignments in the same file we find an import in + +// @filename: globalNs.js +export * from "./cls"; +export as namespace GLO; // TS Only + +// @filename: includeAll.js +import "./bar"; +import "./bin"; +import "./globalNs"; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportSpecifierNonlocal.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportSpecifierNonlocal.ts new file mode 100644 index 0000000000000..a636d19bdec31 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportSpecifierNonlocal.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: source.js +export class Thing {} +export class OtherThing {} +// @filename: index.js +export { Thing, OtherThing as default } from "./source"; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportSubAssignments.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportSubAssignments.ts new file mode 100644 index 0000000000000..f5feb4605d3e8 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsExportSubAssignments.ts @@ -0,0 +1,13 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: cls.js +const Strings = { + a: "A", + b: "B" +}; +class Foo {} +module.exports = Foo; +module.exports.Strings = Strings; \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionClassesCjsExportAssignment.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionClassesCjsExportAssignment.ts new file mode 100644 index 0000000000000..cb2cf9968d8a5 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionClassesCjsExportAssignment.ts @@ -0,0 +1,74 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: timer.js +/** + * @param {number} timeout + */ +function Timer(timeout) { + this.timeout = timeout; +} +module.exports = Timer; +// @filename: hook.js +/** + * @typedef {(arg: import("./context")) => void} HookHandler + */ +/** + * @param {HookHandler} handle + */ +function Hook(handle) { + this.handle = handle; +} +module.exports = Hook; + +// @filename: context.js +/** + * Imports + * + * @typedef {import("./timer")} Timer + * @typedef {import("./hook")} Hook + * @typedef {import("./hook").HookHandler} HookHandler + */ + +/** + * Input type definition + * + * @typedef {Object} Input + * @prop {Timer} timer + * @prop {Hook} hook + */ + +/** + * State type definition + * + * @typedef {Object} State + * @prop {Timer} timer + * @prop {Hook} hook + */ + +/** + * New `Context` + * + * @class + * @param {Input} input + */ + +function Context(input) { + if (!(this instanceof Context)) { + return new Context(input) + } + this.state = this.construct(input); +} +Context.prototype = { + /** + * @param {Input} input + * @param {HookHandler=} handle + * @returns {State} + */ + construct(input, handle = () => void 0) { + return input; + } +} +module.exports = Context; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionJSDoc.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionJSDoc.ts new file mode 100644 index 0000000000000..cfa747d48c8b6 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionJSDoc.ts @@ -0,0 +1,40 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: source.js +/** + * Foos a bar together using an `a` and a `b` + * @param {number} a + * @param {string} b + */ +export function foo(a, b) {} + +/** + * Legacy - DO NOT USE + */ +export class Aleph { + /** + * Impossible to construct. + * @param {Aleph} a + * @param {null} b + */ + constructor(a, b) { + /** + * Field is always null + */ + this.field = b; + } + + /** + * Doesn't actually do anything + * @returns {void} + */ + doIt() {} +} + +/** + * Not the speed of light + */ +export const c = 12; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses.ts new file mode 100644 index 0000000000000..0732fcfa6b302 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses.ts @@ -0,0 +1,29 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: source.js + +/** + * @param {number} x + * @param {number} y + */ +export function Point(x, y) { + if (!(this instanceof Point)) { + return new Point(x, y); + } + this.x = x; + this.y = y; +} + +// @filename: referencer.js + +import {Point} from "./source"; + +/** + * @param {Point} p + */ +export function magnitude(p) { + return Math.sqrt(p.x ** 2 + p.y ** 2); +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses2.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses2.ts new file mode 100644 index 0000000000000..dc58d1e05b4ca --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionLikeClasses2.ts @@ -0,0 +1,81 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: source.js + +/** + * @param {number} len + */ +export function Vec(len) { + /** + * @type {number[]} + */ + this.storage = new Array(len); +} + +Vec.prototype = { + /** + * @param {Vec} other + */ + dot(other) { + if (other.storage.length !== this.storage.length) { + throw new Error(`Dot product only applicable for vectors of equal length`); + } + let sum = 0; + for (let i = 0; i < this.storage.length; i++) { + sum += (this.storage[i] * other.storage[i]); + } + return sum; + }, + magnitude() { + let sum = 0; + for (let i = 0; i < this.storage.length; i++) { + sum += (this.storage[i] ** 2); + } + return Math.sqrt(sum); + } +} + +/** + * @param {number} x + * @param {number} y + */ +export function Point2D(x, y) { + if (!(this instanceof Point2D)) { + return new Point2D(x, y); + } + Vec.call(this, 2); + this.x = x; + this.y = y; +} + +Point2D.prototype = { + __proto__: Vec, + get x() { + return this.storage[0]; + }, + /** + * @param {number} x + */ + set x(x) { + this.storage[0] = x; + }, + get y() { + return this.storage[1]; + }, + /** + * @param {number} y + */ + set y(y) { + this.storage[1] = y; + } +}; + +// @filename: referencer.js + +import {Point2D} from "./source"; + +export const origin = new Point2D(0, 0); +// export const res = Point2D(2, 3).dot(origin); // TODO: when __proto__ works, validate this diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctions.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctions.ts new file mode 100644 index 0000000000000..65247ba282db5 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctions.ts @@ -0,0 +1,62 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @declaration: true +// @filename: index.js +export function a() {} + +export function b() {} +b.cat = "cat"; + +export function c() {} +c.Cls = class {} + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +export function d(a, b) { return /** @type {*} */(null); } + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +export function e(a, b) { return /** @type {*} */(null); } + +/** + * @template T + * @param {T} a + */ +export function f(a) { + return a; +} +f.self = f; + +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function g(a, b) { + return a.x && b.y(); +} + +export { g }; + +/** + * @param {{x: string}} a + * @param {{y: typeof b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} + +export { hh as h }; + +export function i() {} +export { i as ii }; + +export { j as jj }; +export function j() {} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionsCjs.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionsCjs.ts new file mode 100644 index 0000000000000..329ebda040f13 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsFunctionsCjs.ts @@ -0,0 +1,63 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @declaration: true +// @filename: index.js +module.exports.a = function a() {} + +module.exports.b = function b() {} +module.exports.b.cat = "cat"; + +module.exports.c = function c() {} +module.exports.c.Cls = class {} + +/** + * @param {number} a + * @param {number} b + * @return {string} + */ +module.exports.d = function d(a, b) { return /** @type {*} */(null); } + +/** + * @template T,U + * @param {T} a + * @param {U} b + * @return {T & U} + */ +module.exports.e = function e(a, b) { return /** @type {*} */(null); } + +/** + * @template T + * @param {T} a + */ +module.exports.f = function f(a) { + return a; +} +module.exports.f.self = module.exports.f; + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function g(a, b) { + return a.x && b.y(); +} + +module.exports.g = g; + +/** + * @param {{x: string}} a + * @param {{y: typeof module.exports.b}} b + */ +function hh(a, b) { + return a.x && b.y(); +} + +module.exports.h = hh; + +module.exports.i = function i() {} +module.exports.ii = module.exports.i; + +// note that this last one doesn't make much sense in cjs, since exports aren't hoisted bindings +module.exports.jj = module.exports.j; +module.exports.j = function j() {} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsImportTypeBundled.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsImportTypeBundled.ts new file mode 100644 index 0000000000000..aa6a5f475466d --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsImportTypeBundled.ts @@ -0,0 +1,19 @@ +// @allowJs: true +// @checkJs: true +// @outFile: out.js +// @module: amd +// @declaration: true +// @filename: folder/mod1.js +/** + * @typedef {{x: number}} Item + */ +/** + * @type {Item}; + */ +const x = {x: 12}; +module.exports = x; +// @filename: index.js + +/** @type {(typeof import("./folder/mod1"))[]} */ +const items = [{x: 12}]; +module.exports = items; \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsInterfaces.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsInterfaces.ts new file mode 100644 index 0000000000000..1eb04215792f4 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsInterfaces.ts @@ -0,0 +1,125 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: index.js + +// Pretty much all of this should be an error, (since interfaces are forbidden in js), +// but we should be able to synthesize declarations from the symbols regardless + +export interface A {} + +export interface B { + cat: string; +} + +export interface C { + field: T & U; + optionalField?: T; + readonly readonlyField: T & U; + readonly readonlyOptionalField?: U; + (): number; + (x: T): U; + (x: Q): T & Q; + + new (): string; + new (x: T): U; + new (x: Q): T & Q; + + method(): number; + method(a: T & Q): Q & number; + method(a?: number): number; + method(...args: any[]): number; + + optMethod?(): number; +} + +interface G {} + +export { G }; + +interface HH {} + +export { HH as H }; + +export interface I {} +export { I as II }; + +export { J as JJ }; +export interface J {} + +export interface K extends I,J { + x: string; +} + +export interface L extends K { + y: string; +} + +export interface M { + field: T; +} + +export interface N extends M { + other: U; +} + +export interface O { + [idx: string]: string; +} + +export interface P extends O {} + +export interface Q extends O { + [idx: string]: "ok"; +} + +export interface R extends O { + [idx: number]: "ok"; +} + +export interface S extends O { + [idx: string]: "ok"; + [idx: number]: never; +} + +export interface T { + [idx: number]: string; +} + +export interface U extends T {} + + +export interface V extends T { + [idx: string]: string; +} + +export interface W extends T { + [idx: number]: "ok"; +} + +export interface X extends T { + [idx: string]: string; + [idx: number]: "ok"; +} + +export interface Y { + [idx: string]: {x: number}; + [idx: number]: {x: number, y: number}; +} + +export interface Z extends Y {} + +export interface AA extends Y { + [idx: string]: {x: number, y: number}; +} + +export interface BB extends Y { + [idx: number]: {x: 0, y: 0}; +} + +export interface CC extends Y { + [idx: string]: {x: number, y: number}; + [idx: number]: {x: 0, y: 0}; +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsJson.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsJson.ts new file mode 100644 index 0000000000000..a98c41d172827 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsJson.ts @@ -0,0 +1,17 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @resolveJsonModule: true +// @outDir: ./out +// @declaration: true +// @filename: index.js +const j = require("./obj.json"); +module.exports = j; +// @filename: obj.json +{ + "x": 12, + "y": 12, + "obj": { + "items": [{"x": 12}, {"x": 12, "y": 12}, {"x": 0}, {"x": -1, "err": true}] + } +} \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsMultipleExportFromMerge.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsMultipleExportFromMerge.ts new file mode 100644 index 0000000000000..c8e2ef3e4088d --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsMultipleExportFromMerge.ts @@ -0,0 +1,23 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: items.js +export const a = 1; +export const b = 2; +export const c = 3; + +// @filename: justone.js +export { a, b, c } from "./items"; + +// @filename: two.js +export { a } from "./items"; +export { b, c } from "./items"; + +// @filename: multiple.js +export {a, b} from "./items"; +export {a as aa} from "./two"; +export {b as bb} from "./two"; +export {c} from "./two" +export {c as cc} from "./items"; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsPackageJson.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsPackageJson.ts new file mode 100644 index 0000000000000..7a6b8180f74d9 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsPackageJson.ts @@ -0,0 +1,42 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @resolveJsonModule: true +// @outDir: ./out +// @declaration: true +// @filename: index.js +const j = require("./package.json"); +module.exports = j; +// @filename: package.json +{ + "name": "pkg", + "version": "0.1.0", + "description": "A package", + "main": "./dist/index.js", + "bin": { + "cli": "./bin/cli.js", + }, + "engines": { + "node": ">=0" + }, + "scripts": { + "scriptname": "run && run again", + }, + "devDependencies": { + "@ns/dep": "0.1.2", + }, + "dependencies": { + "dep": "1.2.3", + }, + "repository": "microsoft/TypeScript", + "keywords": [ + "kw" + ], + "author": "Auth", + "license": "See Licensce", + "homepage": "https://site", + "config": { + "o": ["a"] + } +} + \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReexportAliases.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReexportAliases.ts new file mode 100644 index 0000000000000..3160df7f12853 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReexportAliases.ts @@ -0,0 +1,14 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @filename: cls.js +export default class Foo {} + +// @filename: usage.js +import {default as Fooa} from "./cls"; + +export const x = new Fooa(); + +export {default as Foob} from "./cls"; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReexportAliasesEsModuleInterop.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReexportAliasesEsModuleInterop.ts new file mode 100644 index 0000000000000..94bb9fe235a20 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReexportAliasesEsModuleInterop.ts @@ -0,0 +1,16 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: ./out +// @declaration: true +// @esModuleInterop: true +// @filename: cls.js +class Foo {} +module.exports = Foo; + +// @filename: usage.js +import {default as Fooa} from "./cls"; + +export const x = new Fooa(); + +export {default as Foob} from "./cls"; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReusesExistingNodesMappingJSDocTypes.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReusesExistingNodesMappingJSDocTypes.ts new file mode 100644 index 0000000000000..3c7293ceb824a --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsReusesExistingNodesMappingJSDocTypes.ts @@ -0,0 +1,30 @@ +// @allowJs: true +// @checkJs: true +// @outDir: /out +// @lib: es6 +// @declaration: true +// @filename: index.js + +/** @type {?} */ +export const a = null; + +/** @type {*} */ +export const b = null; + +/** @type {string?} */ +export const c = null; + +/** @type {string=} */ +export const d = null; + +/** @type {string!} */ +export const e = null; + +/** @type {function(string, number): object} */ +export const f = null; + +/** @type {function(new: object, string, number)} */ +export const g = null; + +/** @type {Object.} */ +export const h = null; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeAliases.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeAliases.ts new file mode 100644 index 0000000000000..84ee3f53c9154 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeAliases.ts @@ -0,0 +1,54 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @declaration: true +// @filename: index.js + +export {}; // flag file as module +/** + * @typedef {string | number | symbol} PropName + */ + +/** + * Callback + * + * @callback NumberToStringCb + * @param {number} a + * @returns {string} + */ + +/** + * @template T + * @typedef {T & {name: string}} MixinName + */ + +/** + * Identity function + * + * @template T + * @callback Identity + * @param {T} x + * @returns {T} + */ + +// @filename: mixed.js +/** + * @typedef {{x: string} | number | LocalThing | ExportedThing} SomeType + */ +/** + * @param {number} x + * @returns {SomeType} + */ +function doTheThing(x) { + return {x: ""+x}; +} +class ExportedThing { + z = "ok" +} +module.exports = { + doTheThing, + ExportedThing, +}; +class LocalThing { + y = "ok" +} diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReassignmentFromDeclaration.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReassignmentFromDeclaration.ts new file mode 100644 index 0000000000000..1d4119c58068b --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReassignmentFromDeclaration.ts @@ -0,0 +1,16 @@ +// @allowJs: true +// @checkJs: true +// @outDir: /out +// @lib: es6 +// @declaration: true +// @filename: /some-mod.d.ts +interface Item { + x: string; +} +declare const items: Item[]; +export = items; +// @filename: index.js + +/** @type {typeof import("/some-mod")} */ +const items = []; +module.exports = items; \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReassignmentFromDeclaration2.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReassignmentFromDeclaration2.ts new file mode 100644 index 0000000000000..2a48213d0db88 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReassignmentFromDeclaration2.ts @@ -0,0 +1,15 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @lib: es6 +// @declaration: true +// @filename: some-mod.d.ts +interface Item { + x: string; +} +declare function getItems(): Item[]; +export = getItems; +// @filename: index.js + +const items = require("./some-mod")(); +module.exports = items; \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReferences.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReferences.ts new file mode 100644 index 0000000000000..29151bf965625 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypeReferences.ts @@ -0,0 +1,19 @@ +// @allowJs: true +// @checkJs: true +// @target: es5 +// @outDir: tests/cases/conformance/jsdoc/declarations/out +// @declaration: true +// @filename: node_modules/@types/node/index.d.ts +declare module "fs" { + export class Something {} +} +// @filename: index.js +/// + +const Something = require("fs").Something; + +const thing = new Something(); + +module.exports = { + thing +}; \ No newline at end of file diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefAndImportTypes.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefAndImportTypes.ts new file mode 100644 index 0000000000000..3b5fb6439f431 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefAndImportTypes.ts @@ -0,0 +1,38 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @declaration: true +// @filename: conn.js + +/** + * @typedef {string | number} Whatever + */ + +class Conn { + constructor() {} + item = 3; + method() {} +} + +module.exports = Conn; + +// @filename: usage.js + +/** + * @typedef {import("./conn")} Conn + */ + +class Wrap { + /** + * @param {Conn} c + */ + constructor(c) { + this.connItem = c.item; + /** @type {import("./conn").Whatever} */ + this.another = ""; + } +} + +module.exports = { + Wrap +}; diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefDescriptionsPreserved.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefDescriptionsPreserved.ts new file mode 100644 index 0000000000000..d4583d53a4f21 --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefDescriptionsPreserved.ts @@ -0,0 +1,21 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @declaration: true +// @filename: index.js + +/** + * Options for Foo <------------ + * @typedef {Object} FooOptions + * @property {boolean} bar - Marvin K Mooney + * @property {string} baz - Sylvester McMonkey McBean + */ + +/** + * Multiline + * Options + * for Foo <------------ + * @typedef {Object} BarOptions + * @property {boolean} bar - Marvin K Mooney + * @property {string} baz - Sylvester McMonkey McBean + */ diff --git a/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefPropertyAndExportAssignment.ts b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefPropertyAndExportAssignment.ts new file mode 100644 index 0000000000000..16d63e0aec40d --- /dev/null +++ b/tests/cases/conformance/jsdoc/declarations/jsDeclarationsTypedefPropertyAndExportAssignment.ts @@ -0,0 +1,59 @@ +// @allowJs: true +// @checkJs: true +// @outDir: ./out +// @lib: es6 +// @declaration: true +// @filename: module.js + +/** @typedef {'parseHTML'|'styleLayout'} TaskGroupIds */ + +/** + * @typedef TaskGroup + * @property {TaskGroupIds} id + * @property {string} label + * @property {string[]} traceEventNames + */ + +/** + * @type {{[P in TaskGroupIds]: {id: P, label: string}}} + */ +const taskGroups = { + parseHTML: { + id: 'parseHTML', + label: 'Parse HTML & CSS' + }, + styleLayout: { + id: 'styleLayout', + label: 'Style & Layout' + }, +} + +/** @type {Object} */ +const taskNameToGroup = {}; + +module.exports = { + taskGroups, + taskNameToGroup, +}; +// @filename: index.js +const {taskGroups, taskNameToGroup} = require('./module.js'); + +/** @typedef {import('./module.js').TaskGroup} TaskGroup */ + +/** + * @typedef TaskNode + * @prop {TaskNode[]} children + * @prop {TaskNode|undefined} parent + * @prop {TaskGroup} group + */ + +/** @typedef {{timers: Map}} PriorTaskData */ +class MainThreadTasks { + /** + * @param {TaskGroup} x + * @param {TaskNode} y + */ + constructor(x, y){} +} + +module.exports = MainThreadTasks; \ No newline at end of file diff --git a/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts b/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts index 927d84ed8bace..58090d0ad3155 100644 --- a/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts +++ b/tests/cases/fourslash/jsFileCompilationDuplicateFunctionImplementation.ts @@ -20,7 +20,7 @@ verify.getSemanticDiagnostics([{ }]); verify.verifyGetEmitOutputContentsForCurrentFile([ { name: "out.js", text: "function foo() { return 10; }\r\nfunction foo() { return 30; }\r\n", writeByteOrderMark: false }, - { name: "out.d.ts", text: "", writeByteOrderMark: false }]); + { name: "out.d.ts", text: "declare function foo(): number;\r\ndeclare function foo(): number;\r\n", writeByteOrderMark: false }]); goTo.marker("2"); verify.getSemanticDiagnostics([{ message: "Duplicate function implementation.",