mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'port-master-10-16' into release-2.6
This commit is contained in:
@@ -17,6 +17,7 @@ branches:
|
||||
only:
|
||||
- master
|
||||
- release-2.5
|
||||
- release-2.6
|
||||
|
||||
install:
|
||||
- npm uninstall typescript --no-save
|
||||
|
||||
+16
-10
@@ -3398,7 +3398,7 @@ namespace ts {
|
||||
else if (flags & TypeFormatFlags.WriteClassExpressionAsTypeLiteral &&
|
||||
type.symbol.valueDeclaration &&
|
||||
type.symbol.valueDeclaration.kind === SyntaxKind.ClassExpression) {
|
||||
writeAnonymousType(getDeclaredTypeOfClassOrInterface(type.symbol), flags);
|
||||
writeAnonymousType(type, flags);
|
||||
}
|
||||
else {
|
||||
// Write the type reference in the format f<A>.g<B>.C<X, Y> where A and B are type arguments
|
||||
@@ -5777,7 +5777,7 @@ namespace ts {
|
||||
for (const propertySymbol of getPropertiesOfType(modifiersType)) {
|
||||
addMemberForKeyType(getLiteralTypeFromPropertyName(propertySymbol), propertySymbol);
|
||||
}
|
||||
if (getIndexInfoOfType(modifiersType, IndexKind.String)) {
|
||||
if (modifiersType.flags & TypeFlags.Any || getIndexInfoOfType(modifiersType, IndexKind.String)) {
|
||||
addMemberForKeyType(stringType);
|
||||
}
|
||||
}
|
||||
@@ -5821,7 +5821,7 @@ namespace ts {
|
||||
prop.syntheticLiteralTypeOrigin = t as StringLiteralType;
|
||||
members.set(propName, prop);
|
||||
}
|
||||
else if (t.flags & TypeFlags.String) {
|
||||
else if (t.flags & (TypeFlags.Any | TypeFlags.String)) {
|
||||
stringIndexInfo = createIndexInfo(propType, templateReadonly);
|
||||
}
|
||||
}
|
||||
@@ -8386,7 +8386,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isMappableType(type: Type) {
|
||||
return type.flags & (TypeFlags.TypeParameter | TypeFlags.Object | TypeFlags.Intersection | TypeFlags.IndexedAccess);
|
||||
return type.flags & (TypeFlags.Any | TypeFlags.TypeParameter | TypeFlags.Object | TypeFlags.Intersection | TypeFlags.IndexedAccess);
|
||||
}
|
||||
|
||||
function instantiateAnonymousType(type: AnonymousType, mapper: TypeMapper): AnonymousType {
|
||||
@@ -13182,7 +13182,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Return contextual type of parameter or undefined if no contextual type is available
|
||||
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type {
|
||||
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type | undefined {
|
||||
const func = parameter.parent;
|
||||
if (isContextSensitiveFunctionOrObjectLiteralMethod(func)) {
|
||||
const iife = getImmediatelyInvokedFunctionExpression(func);
|
||||
@@ -13208,7 +13208,12 @@ namespace ts {
|
||||
if (contextualSignature) {
|
||||
const funcHasRestParameters = hasRestParameter(func);
|
||||
const len = func.parameters.length - (funcHasRestParameters ? 1 : 0);
|
||||
const indexOfParameter = indexOf(func.parameters, parameter);
|
||||
let indexOfParameter = indexOf(func.parameters, parameter);
|
||||
if (getThisParameter(func) !== undefined && !contextualSignature.thisParameter) {
|
||||
Debug.assert(indexOfParameter !== 0); // Otherwise we should not have called `getContextuallyTypedParameterType`.
|
||||
indexOfParameter -= 1;
|
||||
}
|
||||
|
||||
if (indexOfParameter < len) {
|
||||
return getTypeAtPosition(contextualSignature, indexOfParameter);
|
||||
}
|
||||
@@ -16834,9 +16839,10 @@ namespace ts {
|
||||
// in a JS file
|
||||
// Note:JS inferred classes might come from a variable declaration instead of a function declaration.
|
||||
// In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration.
|
||||
const funcSymbol = node.expression.kind === SyntaxKind.Identifier ?
|
||||
getResolvedSymbol(node.expression as Identifier) :
|
||||
checkExpression(node.expression).symbol;
|
||||
let funcSymbol = checkExpression(node.expression).symbol;
|
||||
if (!funcSymbol && node.expression.kind === SyntaxKind.Identifier) {
|
||||
funcSymbol = getResolvedSymbol(node.expression as Identifier);
|
||||
}
|
||||
const type = funcSymbol && getJavaScriptClassType(funcSymbol);
|
||||
if (type) {
|
||||
return type;
|
||||
@@ -19667,7 +19673,7 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return typeAsAwaitable.awaitedTypeOfType = getUnionType(types, /*subtypeReduction*/ true);
|
||||
return typeAsAwaitable.awaitedTypeOfType = getUnionType(types);
|
||||
}
|
||||
|
||||
const promisedType = getPromisedTypeOfPromise(type);
|
||||
|
||||
@@ -3754,12 +3754,20 @@
|
||||
"category": "Message",
|
||||
"code": 95008
|
||||
},
|
||||
"Infer type of '{0}' from usage.": {
|
||||
"Annotate with type from JSDoc": {
|
||||
"category": "Message",
|
||||
"code": 95009
|
||||
},
|
||||
"Infer parameter types from usage.": {
|
||||
"Annotate with types from JSDoc": {
|
||||
"category": "Message",
|
||||
"code": 95010
|
||||
},
|
||||
"Infer type of '{0}' from usage.": {
|
||||
"category": "Message",
|
||||
"code": 95011
|
||||
},
|
||||
"Infer parameter types from usage.": {
|
||||
"category": "Message",
|
||||
"code": 95012
|
||||
}
|
||||
}
|
||||
|
||||
+53
-2
@@ -546,6 +546,8 @@ namespace ts {
|
||||
return emitTypeReference(<TypeReferenceNode>node);
|
||||
case SyntaxKind.FunctionType:
|
||||
return emitFunctionType(<FunctionTypeNode>node);
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
return emitJSDocFunctionType(node as JSDocFunctionType);
|
||||
case SyntaxKind.ConstructorType:
|
||||
return emitConstructorType(<ConstructorTypeNode>node);
|
||||
case SyntaxKind.TypeQuery:
|
||||
@@ -574,6 +576,20 @@ namespace ts {
|
||||
return emitMappedType(<MappedTypeNode>node);
|
||||
case SyntaxKind.LiteralType:
|
||||
return emitLiteralType(<LiteralTypeNode>node);
|
||||
case SyntaxKind.JSDocAllType:
|
||||
write("*");
|
||||
return;
|
||||
case SyntaxKind.JSDocUnknownType:
|
||||
write("?");
|
||||
return;
|
||||
case SyntaxKind.JSDocNullableType:
|
||||
return emitJSDocNullableType(node as JSDocNullableType);
|
||||
case SyntaxKind.JSDocNonNullableType:
|
||||
return emitJSDocNonNullableType(node as JSDocNonNullableType);
|
||||
case SyntaxKind.JSDocOptionalType:
|
||||
return emitJSDocOptionalType(node as JSDocOptionalType);
|
||||
case SyntaxKind.JSDocVariadicType:
|
||||
return emitJSDocVariadicType(node as JSDocVariadicType);
|
||||
|
||||
// Binding patterns
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
@@ -914,9 +930,16 @@ namespace ts {
|
||||
emitDecorators(node, node.decorators);
|
||||
emitModifiers(node, node.modifiers);
|
||||
emitIfPresent(node.dotDotDotToken);
|
||||
emit(node.name);
|
||||
if (node.name) {
|
||||
emit(node.name);
|
||||
}
|
||||
emitIfPresent(node.questionToken);
|
||||
emitWithPrefix(": ", node.type);
|
||||
if (node.parent && node.parent.kind === SyntaxKind.JSDocFunctionType && !node.name) {
|
||||
emit(node.type);
|
||||
}
|
||||
else {
|
||||
emitWithPrefix(": ", node.type);
|
||||
}
|
||||
emitExpressionWithPrefix(" = ", node.initializer);
|
||||
}
|
||||
|
||||
@@ -1035,6 +1058,29 @@ namespace ts {
|
||||
emit(node.type);
|
||||
}
|
||||
|
||||
function emitJSDocFunctionType(node: JSDocFunctionType) {
|
||||
write("function");
|
||||
emitParameters(node, node.parameters);
|
||||
write(":");
|
||||
emit(node.type);
|
||||
}
|
||||
|
||||
|
||||
function emitJSDocNullableType(node: JSDocNullableType) {
|
||||
write("?");
|
||||
emit(node.type);
|
||||
}
|
||||
|
||||
function emitJSDocNonNullableType(node: JSDocNonNullableType) {
|
||||
write("!");
|
||||
emit(node.type);
|
||||
}
|
||||
|
||||
function emitJSDocOptionalType(node: JSDocOptionalType) {
|
||||
emit(node.type);
|
||||
write("=");
|
||||
}
|
||||
|
||||
function emitConstructorType(node: ConstructorTypeNode) {
|
||||
write("new ");
|
||||
emitTypeParameters(node, node.typeParameters);
|
||||
@@ -1060,6 +1106,11 @@ namespace ts {
|
||||
write("[]");
|
||||
}
|
||||
|
||||
function emitJSDocVariadicType(node: JSDocVariadicType) {
|
||||
write("...");
|
||||
emit(node.type);
|
||||
}
|
||||
|
||||
function emitTupleType(node: TupleTypeNode) {
|
||||
write("[");
|
||||
emitList(node, node.elementTypes, ListFormat.TupleTypeElements);
|
||||
|
||||
@@ -77,16 +77,20 @@ namespace ts {
|
||||
traceEnabled: boolean;
|
||||
}
|
||||
|
||||
interface PackageJson {
|
||||
name?: string;
|
||||
version?: string;
|
||||
/** Just the fields that we use for module resolution. */
|
||||
interface PackageJsonPathFields {
|
||||
typings?: string;
|
||||
types?: string;
|
||||
main?: string;
|
||||
}
|
||||
|
||||
interface PackageJson extends PackageJsonPathFields {
|
||||
name?: string;
|
||||
version?: string;
|
||||
}
|
||||
|
||||
/** Reads from "main" or "types"/"typings" depending on `extensions`. */
|
||||
function tryReadPackageJsonFields(readTypes: boolean, jsonContent: PackageJson, baseDirectory: string, state: ModuleResolutionState): string | undefined {
|
||||
function tryReadPackageJsonFields(readTypes: boolean, jsonContent: PackageJsonPathFields, baseDirectory: string, state: ModuleResolutionState): string | undefined {
|
||||
return readTypes ? tryReadFromField("typings") || tryReadFromField("types") : tryReadFromField("main");
|
||||
|
||||
function tryReadFromField(fieldName: "typings" | "types" | "main"): string | undefined {
|
||||
@@ -886,7 +890,7 @@ namespace ts {
|
||||
return withPackageId(packageId, loadNodeModuleFromDirectoryWorker(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, packageJsonContent));
|
||||
}
|
||||
|
||||
function loadNodeModuleFromDirectoryWorker(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState, packageJsonContent: PackageJson | undefined): PathAndExtension | undefined {
|
||||
function loadNodeModuleFromDirectoryWorker(extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, onlyRecordFailures: boolean, state: ModuleResolutionState, packageJsonContent: PackageJsonPathFields | undefined): PathAndExtension | undefined {
|
||||
const fromPackageJson = packageJsonContent && loadModuleFromPackageJson(packageJsonContent, extensions, candidate, failedLookupLocations, state);
|
||||
if (fromPackageJson) {
|
||||
return fromPackageJson;
|
||||
@@ -901,7 +905,7 @@ namespace ts {
|
||||
failedLookupLocations: Push<string>,
|
||||
onlyRecordFailures: boolean,
|
||||
{ host, traceEnabled }: ModuleResolutionState,
|
||||
): { packageJsonContent: PackageJson | undefined, packageId: PackageId | undefined } {
|
||||
): { found: boolean, packageJsonContent: PackageJsonPathFields | undefined, packageId: PackageId | undefined } {
|
||||
const directoryExists = !onlyRecordFailures && directoryProbablyExists(nodeModuleDirectory, host);
|
||||
const packageJsonPath = pathToPackageJson(nodeModuleDirectory);
|
||||
if (directoryExists && host.fileExists(packageJsonPath)) {
|
||||
@@ -912,7 +916,7 @@ namespace ts {
|
||||
const packageId: PackageId = typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string"
|
||||
? { name: packageJsonContent.name, subModuleName, version: packageJsonContent.version }
|
||||
: undefined;
|
||||
return { packageJsonContent, packageId };
|
||||
return { found: true, packageJsonContent, packageId };
|
||||
}
|
||||
else {
|
||||
if (directoryExists && traceEnabled) {
|
||||
@@ -920,11 +924,11 @@ namespace ts {
|
||||
}
|
||||
// record package json as one of failed lookup locations - in the future if this file will appear it will invalidate resolution results
|
||||
failedLookupLocations.push(packageJsonPath);
|
||||
return { packageJsonContent: undefined, packageId: undefined };
|
||||
return { found: false, packageJsonContent: undefined, packageId: undefined };
|
||||
}
|
||||
}
|
||||
|
||||
function loadModuleFromPackageJson(jsonContent: PackageJson, extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): PathAndExtension | undefined {
|
||||
function loadModuleFromPackageJson(jsonContent: PackageJsonPathFields, extensions: Extensions, candidate: string, failedLookupLocations: Push<string>, state: ModuleResolutionState): PathAndExtension | undefined {
|
||||
const file = tryReadPackageJsonFields(extensions !== Extensions.JavaScript, jsonContent, candidate, state);
|
||||
if (!file) {
|
||||
return undefined;
|
||||
@@ -976,10 +980,22 @@ namespace ts {
|
||||
}
|
||||
|
||||
function loadModuleFromNodeModulesFolder(extensions: Extensions, moduleName: string, nodeModulesFolder: string, nodeModulesFolderExists: boolean, failedLookupLocations: Push<string>, state: ModuleResolutionState): Resolved | undefined {
|
||||
const { packageName, rest } = getPackageName(moduleName);
|
||||
const packageRootPath = combinePaths(nodeModulesFolder, packageName);
|
||||
const { packageJsonContent, packageId } = getPackageJsonInfo(packageRootPath, rest, failedLookupLocations, !nodeModulesFolderExists, state);
|
||||
const candidate = normalizePath(combinePaths(nodeModulesFolder, moduleName));
|
||||
// First look for a nested package.json, as in `node_modules/foo/bar/package.json`.
|
||||
let packageJsonContent: PackageJsonPathFields | undefined;
|
||||
let packageId: PackageId | undefined;
|
||||
const packageInfo = getPackageJsonInfo(candidate, "", failedLookupLocations, /*onlyRecordFailures*/ !nodeModulesFolderExists, state);
|
||||
if (packageInfo.found) {
|
||||
({ packageJsonContent, packageId } = packageInfo);
|
||||
}
|
||||
else {
|
||||
const { packageName, rest } = getPackageName(moduleName);
|
||||
if (rest !== "") { // If "rest" is empty, we just did this search above.
|
||||
const packageRootPath = combinePaths(nodeModulesFolder, packageName);
|
||||
// Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId.
|
||||
packageId = getPackageJsonInfo(packageRootPath, rest, failedLookupLocations, !nodeModulesFolderExists, state).packageId;
|
||||
}
|
||||
}
|
||||
const pathAndExtension = loadModuleFromFile(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state) ||
|
||||
loadNodeModuleFromDirectoryWorker(extensions, candidate, failedLookupLocations, !nodeModulesFolderExists, state, packageJsonContent);
|
||||
return withPackageId(packageId, pathAndExtension);
|
||||
|
||||
@@ -3676,7 +3676,8 @@ namespace ts {
|
||||
// Do not do this in the global scope, as any variable we currently generate could conflict with
|
||||
// variables from outside of the current compilation. In the future, we can revisit this behavior.
|
||||
if (isExternalModule(currentSourceFile)) {
|
||||
const tempVar = createTempVariable(recordTaggedTemplateString);
|
||||
const tempVar = createUniqueName("templateObject");
|
||||
recordTaggedTemplateString(tempVar);
|
||||
templateArguments[0] = createLogicalOr(
|
||||
tempVar,
|
||||
createAssignment(
|
||||
|
||||
@@ -463,7 +463,7 @@ namespace ts {
|
||||
);
|
||||
|
||||
// Mark this node as originally an async function
|
||||
(generatorFunc.emitNode || (generatorFunc.emitNode = {})).flags |= EmitFlags.AsyncFunctionBody;
|
||||
(generatorFunc.emitNode || (generatorFunc.emitNode = {})).flags |= EmitFlags.AsyncFunctionBody | EmitFlags.ReuseTempVariableScope;
|
||||
|
||||
return createCall(
|
||||
getHelperName("__awaiter"),
|
||||
|
||||
@@ -826,7 +826,7 @@ namespace ts {
|
||||
/*needsValue*/ false,
|
||||
createAssignment
|
||||
)
|
||||
: createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression));
|
||||
: node.initializer ? createAssignment(node.name, visitNode(node.initializer, destructuringAndImportCallVisitor, isExpression)) : node.name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1296,6 +1296,9 @@ namespace ts {
|
||||
let expressions: Expression[];
|
||||
for (const variable of node.declarations) {
|
||||
expressions = append(expressions, transformInitializedVariable(variable, /*isExportedDeclaration*/ false));
|
||||
if (!variable.initializer) {
|
||||
hoistBindingElement(variable);
|
||||
}
|
||||
}
|
||||
|
||||
return expressions ? inlineExpressions(expressions) : createOmittedExpression();
|
||||
|
||||
@@ -2700,11 +2700,11 @@ namespace ts {
|
||||
* Gets the effective type annotation of a variable, parameter, or property. If the node was
|
||||
* parsed in a JavaScript file, gets the type annotation from JSDoc.
|
||||
*/
|
||||
export function getEffectiveTypeAnnotationNode(node: VariableLikeDeclaration): TypeNode | undefined {
|
||||
export function getEffectiveTypeAnnotationNode(node: VariableLikeDeclaration, checkJSDoc?: boolean): TypeNode | undefined {
|
||||
if (node.type) {
|
||||
return node.type;
|
||||
}
|
||||
if (isInJavaScriptFile(node)) {
|
||||
if (checkJSDoc || isInJavaScriptFile(node)) {
|
||||
return getJSDocType(node);
|
||||
}
|
||||
}
|
||||
@@ -2713,11 +2713,11 @@ namespace ts {
|
||||
* Gets the effective return type annotation of a signature. If the node was parsed in a
|
||||
* JavaScript file, gets the return type annotation from JSDoc.
|
||||
*/
|
||||
export function getEffectiveReturnTypeNode(node: SignatureDeclaration): TypeNode | undefined {
|
||||
export function getEffectiveReturnTypeNode(node: SignatureDeclaration, checkJSDoc?: boolean): TypeNode | undefined {
|
||||
if (node.type) {
|
||||
return node.type;
|
||||
}
|
||||
if (isInJavaScriptFile(node)) {
|
||||
if (checkJSDoc || isInJavaScriptFile(node)) {
|
||||
return getJSDocReturnType(node);
|
||||
}
|
||||
}
|
||||
@@ -2726,11 +2726,11 @@ namespace ts {
|
||||
* Gets the effective type parameters. If the node was parsed in a
|
||||
* JavaScript file, gets the type parameters from the `@template` tag from JSDoc.
|
||||
*/
|
||||
export function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters): ReadonlyArray<TypeParameterDeclaration> {
|
||||
export function getEffectiveTypeParameterDeclarations(node: DeclarationWithTypeParameters, checkJSDoc?: boolean): ReadonlyArray<TypeParameterDeclaration> {
|
||||
if (node.typeParameters) {
|
||||
return node.typeParameters;
|
||||
}
|
||||
if (isInJavaScriptFile(node)) {
|
||||
if (checkJSDoc || isInJavaScriptFile(node)) {
|
||||
const templateTag = getJSDocTemplateTag(node);
|
||||
return templateTag && templateTag.typeParameters;
|
||||
}
|
||||
@@ -2740,9 +2740,9 @@ namespace ts {
|
||||
* Gets the effective type annotation of the value parameter of a set accessor. If the node
|
||||
* was parsed in a JavaScript file, gets the type annotation from JSDoc.
|
||||
*/
|
||||
export function getEffectiveSetAccessorTypeAnnotationNode(node: SetAccessorDeclaration): TypeNode {
|
||||
export function getEffectiveSetAccessorTypeAnnotationNode(node: SetAccessorDeclaration, checkJSDoc?: boolean): TypeNode {
|
||||
const parameter = getSetAccessorValueParameter(node);
|
||||
return parameter && getEffectiveTypeAnnotationNode(parameter);
|
||||
return parameter && getEffectiveTypeAnnotationNode(parameter, checkJSDoc);
|
||||
}
|
||||
|
||||
export function emitNewLineBeforeLeadingComments(lineMap: ReadonlyArray<number>, writer: EmitTextWriter, node: TextRange, leadingComments: ReadonlyArray<CommentRange>) {
|
||||
@@ -5130,7 +5130,14 @@ namespace ts {
|
||||
|| kind === SyntaxKind.UndefinedKeyword
|
||||
|| kind === SyntaxKind.NullKeyword
|
||||
|| kind === SyntaxKind.NeverKeyword
|
||||
|| kind === SyntaxKind.ExpressionWithTypeArguments;
|
||||
|| kind === SyntaxKind.ExpressionWithTypeArguments
|
||||
|| kind === SyntaxKind.JSDocAllType
|
||||
|| kind === SyntaxKind.JSDocUnknownType
|
||||
|| kind === SyntaxKind.JSDocNullableType
|
||||
|| kind === SyntaxKind.JSDocNonNullableType
|
||||
|| kind === SyntaxKind.JSDocOptionalType
|
||||
|| kind === SyntaxKind.JSDocFunctionType
|
||||
|| kind === SyntaxKind.JSDocVariadicType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -844,9 +844,7 @@ namespace Harness {
|
||||
export const es2015DefaultLibFileName = "lib.es2015.d.ts";
|
||||
|
||||
// Cache of lib files from "built/local"
|
||||
const libFileNameSourceFileMap = ts.createMapFromTemplate<ts.SourceFile>({
|
||||
[defaultLibFileName]: createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest)
|
||||
});
|
||||
let libFileNameSourceFileMap: ts.Map<ts.SourceFile> | undefined;
|
||||
|
||||
// Cache of lib files from "tests/lib/"
|
||||
const testLibFileNameSourceFileMap = ts.createMap<ts.SourceFile>();
|
||||
@@ -857,6 +855,12 @@ namespace Harness {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (!libFileNameSourceFileMap) {
|
||||
libFileNameSourceFileMap = ts.createMapFromTemplate({
|
||||
[defaultLibFileName]: createSourceFileAndAssertInvariants(defaultLibFileName, IO.readFile(libFolder + "lib.es5.d.ts"), /*languageVersion*/ ts.ScriptTarget.Latest)
|
||||
});
|
||||
}
|
||||
|
||||
let sourceFile = libFileNameSourceFileMap.get(fileName);
|
||||
if (!sourceFile) {
|
||||
libFileNameSourceFileMap.set(fileName, sourceFile = createSourceFileAndAssertInvariants(fileName, IO.readFile(libFolder + fileName), ts.ScriptTarget.Latest));
|
||||
|
||||
@@ -392,7 +392,7 @@ export = C;
|
||||
});
|
||||
|
||||
describe("Files with different casing", () => {
|
||||
const library = createSourceFile("lib.d.ts", "", ScriptTarget.ES5);
|
||||
let library: SourceFile;
|
||||
function test(files: Map<string>, options: CompilerOptions, currentDirectory: string, useCaseSensitiveFileNames: boolean, rootFiles: string[], diagnosticCodes: number[]): void {
|
||||
const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
|
||||
if (!useCaseSensitiveFileNames) {
|
||||
@@ -406,6 +406,9 @@ export = C;
|
||||
const host: CompilerHost = {
|
||||
getSourceFile: (fileName: string, languageVersion: ScriptTarget) => {
|
||||
if (fileName === "lib.d.ts") {
|
||||
if (!library) {
|
||||
library = createSourceFile("lib.d.ts", "", ScriptTarget.ES5);
|
||||
}
|
||||
return library;
|
||||
}
|
||||
const path = getCanonicalFileName(normalizePath(combinePaths(currentDirectory, fileName)));
|
||||
|
||||
Vendored
+5
-7
@@ -4833,6 +4833,7 @@ interface HTMLFormElement extends HTMLElement {
|
||||
* Fires when a FORM is about to be submitted.
|
||||
*/
|
||||
submit(): void;
|
||||
reportValidity(): boolean;
|
||||
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLFormElement, ev: HTMLElementEventMap[K]) => any, useCapture?: boolean): void;
|
||||
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
|
||||
[name: string]: any;
|
||||
@@ -4961,9 +4962,6 @@ interface HTMLFrameSetElement extends HTMLElement {
|
||||
onafterprint: (this: HTMLFrameSetElement, ev: Event) => any;
|
||||
onbeforeprint: (this: HTMLFrameSetElement, ev: Event) => any;
|
||||
onbeforeunload: (this: HTMLFrameSetElement, ev: BeforeUnloadEvent) => any;
|
||||
/**
|
||||
* Fires when the object receives focus.
|
||||
*/
|
||||
onhashchange: (this: HTMLFrameSetElement, ev: HashChangeEvent) => any;
|
||||
onmessage: (this: HTMLFrameSetElement, ev: MessageEvent) => any;
|
||||
onoffline: (this: HTMLFrameSetElement, ev: Event) => any;
|
||||
@@ -5108,7 +5106,6 @@ interface HTMLIFrameElement extends HTMLElement, GetSVGDocument {
|
||||
* Sets or retrieves whether the user can resize the frame.
|
||||
*/
|
||||
noResize: boolean;
|
||||
|
||||
readonly sandbox: DOMSettableTokenList;
|
||||
/**
|
||||
* Sets or retrieves whether the frame can be scrolled.
|
||||
@@ -8205,6 +8202,7 @@ interface Navigator extends Object, NavigatorID, NavigatorOnLine, NavigatorConte
|
||||
readonly pointerEnabled: boolean;
|
||||
readonly serviceWorker: ServiceWorkerContainer;
|
||||
readonly webdriver: boolean;
|
||||
readonly doNotTrack: string | null;
|
||||
readonly hardwareConcurrency: number;
|
||||
readonly languages: string[];
|
||||
getGamepads(): Gamepad[];
|
||||
@@ -13257,7 +13255,7 @@ interface Window extends EventTarget, WindowTimers, WindowSessionStorage, Window
|
||||
moveBy(x?: number, y?: number): void;
|
||||
moveTo(x?: number, y?: number): void;
|
||||
msWriteProfilerMark(profilerMarkName: string): void;
|
||||
open(url?: string, target?: string, features?: string, replace?: boolean): Window;
|
||||
open(url?: string, target?: string, features?: string, replace?: boolean): Window | null;
|
||||
postMessage(message: any, targetOrigin: string, transfer?: any[]): void;
|
||||
print(): void;
|
||||
prompt(message?: string, _default?: string): string | null;
|
||||
@@ -14006,7 +14004,7 @@ interface EcKeyAlgorithm extends KeyAlgorithm {
|
||||
typedCurve: string;
|
||||
}
|
||||
|
||||
interface EcKeyImportParams {
|
||||
interface EcKeyImportParams extends Algorithm {
|
||||
namedCurve: string;
|
||||
}
|
||||
|
||||
@@ -14657,7 +14655,7 @@ declare function matchMedia(mediaQuery: string): MediaQueryList;
|
||||
declare function moveBy(x?: number, y?: number): void;
|
||||
declare function moveTo(x?: number, y?: number): void;
|
||||
declare function msWriteProfilerMark(profilerMarkName: string): void;
|
||||
declare function open(url?: string, target?: string, features?: string, replace?: boolean): Window;
|
||||
declare function open(url?: string, target?: string, features?: string, replace?: boolean): Window | null;
|
||||
declare function postMessage(message: any, targetOrigin: string, transfer?: any[]): void;
|
||||
declare function print(): void;
|
||||
declare function prompt(message?: string, _default?: string): string | null;
|
||||
|
||||
Vendored
+1
-1
@@ -1642,7 +1642,7 @@ interface EcKeyAlgorithm extends KeyAlgorithm {
|
||||
typedCurve: string;
|
||||
}
|
||||
|
||||
interface EcKeyImportParams {
|
||||
interface EcKeyImportParams extends Algorithm {
|
||||
namedCurve: string;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -242,10 +242,16 @@ namespace ts.server {
|
||||
this.markAsDirty();
|
||||
}
|
||||
|
||||
// Method of LanguageServiceHost
|
||||
getCompilationSettings() {
|
||||
return this.compilerOptions;
|
||||
}
|
||||
|
||||
// Method to support public API
|
||||
getCompilerOptions() {
|
||||
return this.getCompilationSettings();
|
||||
}
|
||||
|
||||
getNewLine() {
|
||||
return this.directoryStructureHost.newLine;
|
||||
}
|
||||
|
||||
@@ -9,16 +9,19 @@ namespace ts.formatting {
|
||||
}
|
||||
|
||||
/**
|
||||
* Computed indentation for a given position in source file
|
||||
* @param position - position in file
|
||||
* @param sourceFile - target source file
|
||||
* @param options - set of editor options that control indentation
|
||||
* @param assumeNewLineBeforeCloseBrace - false when getIndentation is called on the text from the real source file.
|
||||
* true - when we need to assume that position is on the newline. This is usefult for codefixes, i.e.
|
||||
* @param assumeNewLineBeforeCloseBrace
|
||||
* `false` when called on text from a real source file.
|
||||
* `true` when we need to assume `position` is on a newline.
|
||||
*
|
||||
* This is useful for codefixes. Consider
|
||||
* ```
|
||||
* function f() {
|
||||
* |}
|
||||
* when inserting some text after open brace we would like to get the value of indentation as if newline was already there.
|
||||
* However by default indentation at position | will be 0 so 'assumeNewLineBeforeCloseBrace' allows to override this behavior,
|
||||
* ```
|
||||
* with `position` at `|`.
|
||||
*
|
||||
* When inserting some text after an open brace, we would like to get indentation as if a newline was already there.
|
||||
* By default indentation at `position` will be 0 so 'assumeNewLineBeforeCloseBrace' overrides this behavior.
|
||||
*/
|
||||
export function getIndentation(position: number, sourceFile: SourceFile, options: EditorSettings, assumeNewLineBeforeCloseBrace = false): number {
|
||||
if (position > sourceFile.text.length) {
|
||||
@@ -157,10 +160,11 @@ namespace ts.formatting {
|
||||
options: EditorSettings): number {
|
||||
|
||||
let parent: Node = current.parent;
|
||||
let parentStart: LineAndCharacter;
|
||||
let containingListOrParentStart: LineAndCharacter;
|
||||
|
||||
// walk upwards and collect indentations for pairs of parent-child nodes
|
||||
// indentation is not added if parent and child nodes start on the same line or if parent is IfStatement and child starts on the same line with 'else clause'
|
||||
// Walk up the tree and collect indentation for parent-child node pairs. Indentation is not added if
|
||||
// * parent and child nodes start on the same line, or
|
||||
// * parent is an IfStatement and child starts on the same line as an 'else clause'.
|
||||
while (parent) {
|
||||
let useActualIndentation = true;
|
||||
if (ignoreActualIndentationRange) {
|
||||
@@ -175,9 +179,10 @@ namespace ts.formatting {
|
||||
return actualIndentation + indentationDelta;
|
||||
}
|
||||
}
|
||||
parentStart = getParentStart(parent, current, sourceFile);
|
||||
|
||||
containingListOrParentStart = getContainingListOrParentStart(parent, current, sourceFile);
|
||||
const parentAndChildShareLine =
|
||||
parentStart.line === currentStart.line ||
|
||||
containingListOrParentStart.line === currentStart.line ||
|
||||
childStartsOnTheSameLineWithElseInIfStatement(parent, current, currentStart.line, sourceFile);
|
||||
|
||||
if (useActualIndentation) {
|
||||
@@ -197,22 +202,30 @@ namespace ts.formatting {
|
||||
indentationDelta += options.indentSize;
|
||||
}
|
||||
|
||||
// In our AST, a call argument's `parent` is the call-expression, not the argument list.
|
||||
// We would like to increase indentation based on the relationship between an argument and its argument-list,
|
||||
// so we spoof the starting position of the (parent) call-expression to match the (non-parent) argument-list.
|
||||
// But, the spoofed start-value could then cause a problem when comparing the start position of the call-expression
|
||||
// to *its* parent (in the case of an iife, an expression statement), adding an extra level of indentation.
|
||||
//
|
||||
// Instead, when at an argument, we unspoof the starting position of the enclosing call expression
|
||||
// *after* applying indentation for the argument.
|
||||
|
||||
const useTrueStart =
|
||||
isArgumentAndStartLineOverlapsExpressionBeingCalled(parent, current, currentStart.line, sourceFile);
|
||||
|
||||
current = parent;
|
||||
currentStart = parentStart;
|
||||
parent = current.parent;
|
||||
currentStart = useTrueStart ? sourceFile.getLineAndCharacterOfPosition(current.getStart()) : containingListOrParentStart;
|
||||
}
|
||||
|
||||
return indentationDelta + getBaseIndentation(options);
|
||||
}
|
||||
|
||||
|
||||
function getParentStart(parent: Node, child: Node, sourceFile: SourceFile): LineAndCharacter {
|
||||
function getContainingListOrParentStart(parent: Node, child: Node, sourceFile: SourceFile): LineAndCharacter {
|
||||
const containingList = getContainingList(child, sourceFile);
|
||||
if (containingList) {
|
||||
return sourceFile.getLineAndCharacterOfPosition(containingList.pos);
|
||||
}
|
||||
|
||||
return sourceFile.getLineAndCharacterOfPosition(parent.getStart(sourceFile));
|
||||
const startPos = containingList ? containingList.pos : parent.getStart(sourceFile);
|
||||
return sourceFile.getLineAndCharacterOfPosition(startPos);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -291,6 +304,16 @@ namespace ts.formatting {
|
||||
return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile));
|
||||
}
|
||||
|
||||
export function isArgumentAndStartLineOverlapsExpressionBeingCalled(parent: Node, child: Node, childStartLine: number, sourceFile: SourceFileLike): boolean {
|
||||
if (!(isCallExpression(parent) && contains(parent.arguments, child))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const expressionOfCallExpressionEnd = parent.expression.getEnd();
|
||||
const expressionOfCallExpressionEndLine = getLineAndCharacterOfPosition(sourceFile, expressionOfCallExpressionEnd).line;
|
||||
return expressionOfCallExpressionEndLine === childStartLine;
|
||||
}
|
||||
|
||||
export function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFileLike): boolean {
|
||||
if (parent.kind === SyntaxKind.IfStatement && (<IfStatement>parent).elseStatement === child) {
|
||||
const elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile);
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
/* @internal */
|
||||
namespace ts.refactor.annotateWithTypeFromJSDoc {
|
||||
const actionName = "annotate";
|
||||
|
||||
const annotateTypeFromJSDoc: Refactor = {
|
||||
name: "Annotate with type from JSDoc",
|
||||
description: Diagnostics.Annotate_with_type_from_JSDoc.message,
|
||||
getEditsForAction: getEditsForAnnotation,
|
||||
getAvailableActions
|
||||
};
|
||||
const annotateFunctionFromJSDoc: Refactor = {
|
||||
name: "Annotate with types from JSDoc",
|
||||
description: Diagnostics.Annotate_with_types_from_JSDoc.message,
|
||||
getEditsForAction: getEditsForFunctionAnnotation,
|
||||
getAvailableActions
|
||||
};
|
||||
|
||||
type DeclarationWithType =
|
||||
| FunctionLikeDeclaration
|
||||
| VariableDeclaration
|
||||
| ParameterDeclaration
|
||||
| PropertySignature
|
||||
| PropertyDeclaration;
|
||||
|
||||
registerRefactor(annotateTypeFromJSDoc);
|
||||
registerRefactor(annotateFunctionFromJSDoc);
|
||||
|
||||
function getAvailableActions(context: RefactorContext): ApplicableRefactorInfo[] | undefined {
|
||||
if (isInJavaScriptFile(context.file)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const node = getTokenAtPosition(context.file, context.startPosition, /*includeJsDocComment*/ false);
|
||||
const decl = findAncestor(node, isDeclarationWithType);
|
||||
if (!decl || decl.type) {
|
||||
return undefined;
|
||||
}
|
||||
const jsdocType = getJSDocType(decl);
|
||||
const isFunctionWithJSDoc = isFunctionLikeDeclaration(decl) && (getJSDocReturnType(decl) || decl.parameters.some(p => !!getJSDocType(p)));
|
||||
const refactor = (isFunctionWithJSDoc || jsdocType && decl.kind === SyntaxKind.Parameter) ? annotateFunctionFromJSDoc :
|
||||
jsdocType ? annotateTypeFromJSDoc :
|
||||
undefined;
|
||||
if (refactor) {
|
||||
return [{
|
||||
name: refactor.name,
|
||||
description: refactor.description,
|
||||
actions: [
|
||||
{
|
||||
description: refactor.description,
|
||||
name: actionName
|
||||
}
|
||||
]
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
function getEditsForAnnotation(context: RefactorContext, action: string): RefactorEditInfo | undefined {
|
||||
if (actionName !== action) {
|
||||
return Debug.fail(`actionName !== action: ${actionName} !== ${action}`);
|
||||
}
|
||||
|
||||
const sourceFile = context.file;
|
||||
const token = getTokenAtPosition(sourceFile, context.startPosition, /*includeJsDocComment*/ false);
|
||||
const decl = findAncestor(token, isDeclarationWithType);
|
||||
const jsdocType = getJSDocType(decl);
|
||||
if (!decl || !jsdocType || decl.type) {
|
||||
return Debug.fail(`!decl || !jsdocType || decl.type: !${decl} || !${jsdocType} || ${decl.type}`);
|
||||
}
|
||||
|
||||
const changeTracker = textChanges.ChangeTracker.fromContext(context);
|
||||
const declarationWithType = addType(decl, transformJSDocType(jsdocType) as TypeNode);
|
||||
suppressLeadingAndTrailingTrivia(declarationWithType);
|
||||
changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, declarationWithType);
|
||||
return {
|
||||
edits: changeTracker.getChanges(),
|
||||
renameFilename: undefined,
|
||||
renameLocation: undefined
|
||||
};
|
||||
}
|
||||
|
||||
function getEditsForFunctionAnnotation(context: RefactorContext, action: string): RefactorEditInfo | undefined {
|
||||
if (actionName !== action) {
|
||||
return Debug.fail(`actionName !== action: ${actionName} !== ${action}`);
|
||||
}
|
||||
|
||||
const sourceFile = context.file;
|
||||
const token = getTokenAtPosition(sourceFile, context.startPosition, /*includeJsDocComment*/ false);
|
||||
const decl = findAncestor(token, isFunctionLikeDeclaration);
|
||||
const changeTracker = textChanges.ChangeTracker.fromContext(context);
|
||||
const functionWithType = addTypesToFunctionLike(decl);
|
||||
suppressLeadingAndTrailingTrivia(functionWithType);
|
||||
changeTracker.replaceRange(sourceFile, { pos: decl.getStart(), end: decl.end }, functionWithType);
|
||||
return {
|
||||
edits: changeTracker.getChanges(),
|
||||
renameFilename: undefined,
|
||||
renameLocation: undefined
|
||||
};
|
||||
}
|
||||
|
||||
function isDeclarationWithType(node: Node): node is DeclarationWithType {
|
||||
return isFunctionLikeDeclaration(node) ||
|
||||
node.kind === SyntaxKind.VariableDeclaration ||
|
||||
node.kind === SyntaxKind.Parameter ||
|
||||
node.kind === SyntaxKind.PropertySignature ||
|
||||
node.kind === SyntaxKind.PropertyDeclaration;
|
||||
}
|
||||
|
||||
function addTypesToFunctionLike(decl: FunctionLikeDeclaration) {
|
||||
const typeParameters = getEffectiveTypeParameterDeclarations(decl, /*checkJSDoc*/ true);
|
||||
const parameters = decl.parameters.map(
|
||||
p => createParameter(p.decorators, p.modifiers, p.dotDotDotToken, p.name, p.questionToken, transformJSDocType(getEffectiveTypeAnnotationNode(p, /*checkJSDoc*/ true)) as TypeNode, p.initializer));
|
||||
const returnType = transformJSDocType(getEffectiveReturnTypeNode(decl, /*checkJSDoc*/ true)) as TypeNode;
|
||||
switch (decl.kind) {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
return createFunctionDeclaration(decl.decorators, decl.modifiers, decl.asteriskToken, decl.name, typeParameters, parameters, returnType, decl.body);
|
||||
case SyntaxKind.Constructor:
|
||||
return createConstructor(decl.decorators, decl.modifiers, parameters, decl.body);
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return createFunctionExpression(decl.modifiers, decl.asteriskToken, (decl as FunctionExpression).name, typeParameters, parameters, returnType, decl.body);
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return createArrowFunction(decl.modifiers, typeParameters, parameters, returnType, decl.equalsGreaterThanToken, decl.body);
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
return createMethod(decl.decorators, decl.modifiers, decl.asteriskToken, decl.name, decl.questionToken, typeParameters, parameters, returnType, decl.body);
|
||||
case SyntaxKind.GetAccessor:
|
||||
return createGetAccessor(decl.decorators, decl.modifiers, decl.name, decl.parameters, returnType, decl.body);
|
||||
case SyntaxKind.SetAccessor:
|
||||
return createSetAccessor(decl.decorators, decl.modifiers, decl.name, parameters, decl.body);
|
||||
default:
|
||||
return Debug.assertNever(decl, `Unexpected SyntaxKind: ${(decl as any).kind}`);
|
||||
}
|
||||
}
|
||||
|
||||
function addType(decl: DeclarationWithType, jsdocType: TypeNode) {
|
||||
switch (decl.kind) {
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return createVariableDeclaration(decl.name, jsdocType, decl.initializer);
|
||||
case SyntaxKind.PropertySignature:
|
||||
return createPropertySignature(decl.modifiers, decl.name, decl.questionToken, jsdocType, decl.initializer);
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
return createProperty(decl.decorators, decl.modifiers, decl.name, decl.questionToken, jsdocType, decl.initializer);
|
||||
default:
|
||||
return Debug.fail(`Unexpected SyntaxKind: ${decl.kind}`);
|
||||
}
|
||||
}
|
||||
|
||||
function transformJSDocType(node: Node): Node | undefined {
|
||||
if (node === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.JSDocAllType:
|
||||
case SyntaxKind.JSDocUnknownType:
|
||||
return createTypeReferenceNode("any", emptyArray);
|
||||
case SyntaxKind.JSDocOptionalType:
|
||||
return transformJSDocOptionalType(node as JSDocOptionalType);
|
||||
case SyntaxKind.JSDocNonNullableType:
|
||||
return transformJSDocType((node as JSDocNonNullableType).type);
|
||||
case SyntaxKind.JSDocNullableType:
|
||||
return transformJSDocNullableType(node as JSDocNullableType);
|
||||
case SyntaxKind.JSDocVariadicType:
|
||||
return transformJSDocVariadicType(node as JSDocVariadicType);
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
return transformJSDocFunctionType(node as JSDocFunctionType);
|
||||
case SyntaxKind.Parameter:
|
||||
return transformJSDocParameter(node as ParameterDeclaration);
|
||||
case SyntaxKind.TypeReference:
|
||||
return transformJSDocTypeReference(node as TypeReferenceNode);
|
||||
default:
|
||||
return visitEachChild(node, transformJSDocType, /*context*/ undefined) as TypeNode;
|
||||
}
|
||||
}
|
||||
|
||||
function transformJSDocOptionalType(node: JSDocOptionalType) {
|
||||
return createUnionTypeNode([visitNode(node.type, transformJSDocType), createTypeReferenceNode("undefined", emptyArray)]);
|
||||
}
|
||||
|
||||
function transformJSDocNullableType(node: JSDocNullableType) {
|
||||
return createUnionTypeNode([visitNode(node.type, transformJSDocType), createTypeReferenceNode("null", emptyArray)]);
|
||||
}
|
||||
|
||||
function transformJSDocVariadicType(node: JSDocVariadicType) {
|
||||
return createArrayTypeNode(visitNode(node.type, transformJSDocType));
|
||||
}
|
||||
|
||||
function transformJSDocFunctionType(node: JSDocFunctionType) {
|
||||
const parameters = node.parameters && node.parameters.map(transformJSDocType);
|
||||
return createFunctionTypeNode(emptyArray, parameters as ParameterDeclaration[], node.type);
|
||||
}
|
||||
|
||||
function transformJSDocParameter(node: ParameterDeclaration) {
|
||||
const index = node.parent.parameters.indexOf(node);
|
||||
const isRest = node.type.kind === SyntaxKind.JSDocVariadicType && index === node.parent.parameters.length - 1;
|
||||
const name = node.name || (isRest ? "rest" : "arg" + index);
|
||||
const dotdotdot = isRest ? createToken(SyntaxKind.DotDotDotToken) : node.dotDotDotToken;
|
||||
return createParameter(node.decorators, node.modifiers, dotdotdot, name, node.questionToken, visitNode(node.type, transformJSDocType), node.initializer);
|
||||
}
|
||||
|
||||
function transformJSDocTypeReference(node: TypeReferenceNode) {
|
||||
let name = node.typeName;
|
||||
let args = node.typeArguments;
|
||||
if (isIdentifier(node.typeName)) {
|
||||
let text = node.typeName.text;
|
||||
switch (node.typeName.text) {
|
||||
case "String":
|
||||
case "Boolean":
|
||||
case "Object":
|
||||
case "Number":
|
||||
text = text.toLowerCase();
|
||||
break;
|
||||
case "array":
|
||||
case "date":
|
||||
case "promise":
|
||||
text = text[0].toUpperCase() + text.slice(1);
|
||||
break;
|
||||
}
|
||||
name = createIdentifier(text);
|
||||
if ((text === "Array" || text === "Promise") && !node.typeArguments) {
|
||||
args = createNodeArray([createTypeReferenceNode("any", emptyArray)]);
|
||||
}
|
||||
else {
|
||||
args = visitNodes(node.typeArguments, transformJSDocType);
|
||||
}
|
||||
}
|
||||
return createTypeReferenceNode(name, args);
|
||||
}
|
||||
}
|
||||
@@ -17,16 +17,16 @@ namespace ts.refactor.convertFunctionToES6Class {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const start = context.startPosition;
|
||||
const node = getTokenAtPosition(context.file, start, /*includeJsDocComment*/ false);
|
||||
const checker = context.program.getTypeChecker();
|
||||
let symbol = checker.getSymbolAtLocation(node);
|
||||
let symbol = getConstructorSymbol(context);
|
||||
if (!symbol) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (symbol && isDeclarationOfFunctionOrClassExpression(symbol)) {
|
||||
if (isDeclarationOfFunctionOrClassExpression(symbol)) {
|
||||
symbol = (symbol.valueDeclaration as VariableDeclaration).initializer.symbol;
|
||||
}
|
||||
|
||||
if (symbol && (symbol.flags & SymbolFlags.Function) && symbol.members && (symbol.members.size > 0)) {
|
||||
if ((symbol.flags & SymbolFlags.Function) && symbol.members && (symbol.members.size > 0)) {
|
||||
return [
|
||||
{
|
||||
name: convertFunctionToES6Class.name,
|
||||
@@ -48,11 +48,8 @@ namespace ts.refactor.convertFunctionToES6Class {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const start = context.startPosition;
|
||||
const sourceFile = context.file;
|
||||
const checker = context.program.getTypeChecker();
|
||||
const token = getTokenAtPosition(sourceFile, start, /*includeJsDocComment*/ false);
|
||||
const ctorSymbol = checker.getSymbolAtLocation(token);
|
||||
const { file: sourceFile } = context;
|
||||
const ctorSymbol = getConstructorSymbol(context);
|
||||
const newLine = context.rulesProvider.getFormatOptions().newLineCharacter;
|
||||
|
||||
const deletedNodes: Node[] = [];
|
||||
@@ -269,4 +266,10 @@ namespace ts.refactor.convertFunctionToES6Class {
|
||||
return filter(source.modifiers, modifier => modifier.kind === kind);
|
||||
}
|
||||
}
|
||||
|
||||
function getConstructorSymbol({ startPosition, file, program }: RefactorContext): Symbol {
|
||||
const checker = program.getTypeChecker();
|
||||
const token = getTokenAtPosition(file, startPosition, /*includeJsDocComment*/ false);
|
||||
return checker.getSymbolAtLocation(token);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
/// <reference path="annotateWithTypeFromJSDoc.ts" />
|
||||
/// <reference path="convertFunctionToEs6Class.ts" />
|
||||
/// <reference path="extractSymbol.ts" />
|
||||
|
||||
@@ -427,8 +427,11 @@ namespace ts {
|
||||
return start < end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes `candidate.start <= position` holds.
|
||||
*/
|
||||
export function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean {
|
||||
return candidate.end > position || !isCompletedNode(candidate, sourceFile);
|
||||
return position < candidate.end || !isCompletedNode(candidate, sourceFile);
|
||||
}
|
||||
|
||||
export function isCompletedNode(n: Node, sourceFile: SourceFile): boolean {
|
||||
|
||||
@@ -7109,6 +7109,7 @@ declare namespace ts.server {
|
||||
getCachedUnresolvedImportsPerFile_TestOnly(): UnresolvedImportsMap;
|
||||
static resolveModule(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void): {};
|
||||
getCompilationSettings(): CompilerOptions;
|
||||
getCompilerOptions(): CompilerOptions;
|
||||
getNewLine(): string;
|
||||
getProjectVersion(): string;
|
||||
getScriptFileNames(): string[];
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
//// [asyncFunctionTempVariableScoping.ts]
|
||||
// https://github.com/Microsoft/TypeScript/issues/19187
|
||||
|
||||
async ({ foo, bar, ...rest }) => bar(await foo);
|
||||
|
||||
//// [asyncFunctionTempVariableScoping.js]
|
||||
// https://github.com/Microsoft/TypeScript/issues/19187
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
var _this = this;
|
||||
(function (_a) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var foo = _a.foo, bar = _a.bar, rest = __rest(_a, ["foo", "bar"]);
|
||||
var _b;
|
||||
return __generator(this, function (_c) {
|
||||
switch (_c.label) {
|
||||
case 0:
|
||||
_b = bar;
|
||||
return [4 /*yield*/, foo];
|
||||
case 1: return [2 /*return*/, _b.apply(void 0, [_c.sent()])];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/asyncFunctionTempVariableScoping.ts ===
|
||||
// https://github.com/Microsoft/TypeScript/issues/19187
|
||||
|
||||
async ({ foo, bar, ...rest }) => bar(await foo);
|
||||
>foo : Symbol(foo, Decl(asyncFunctionTempVariableScoping.ts, 2, 8))
|
||||
>bar : Symbol(bar, Decl(asyncFunctionTempVariableScoping.ts, 2, 13))
|
||||
>rest : Symbol(rest, Decl(asyncFunctionTempVariableScoping.ts, 2, 18))
|
||||
>bar : Symbol(bar, Decl(asyncFunctionTempVariableScoping.ts, 2, 13))
|
||||
>foo : Symbol(foo, Decl(asyncFunctionTempVariableScoping.ts, 2, 8))
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/asyncFunctionTempVariableScoping.ts ===
|
||||
// https://github.com/Microsoft/TypeScript/issues/19187
|
||||
|
||||
async ({ foo, bar, ...rest }) => bar(await foo);
|
||||
>async ({ foo, bar, ...rest }) => bar(await foo) : ({ foo, bar, ...rest }: { [x: string]: any; foo: any; bar: any; }) => Promise<any>
|
||||
>foo : any
|
||||
>bar : any
|
||||
>rest : { [x: string]: any; }
|
||||
>bar(await foo) : any
|
||||
>bar : any
|
||||
>await foo : any
|
||||
>foo : any
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
//// [awaitUnionPromise.ts]
|
||||
/// @target: es2015
|
||||
// https://github.com/Microsoft/TypeScript/issues/18186
|
||||
|
||||
class AsyncEnumeratorDone { };
|
||||
|
||||
interface IAsyncEnumerator<T> {
|
||||
next1(): Promise<T | AsyncEnumeratorDone>;
|
||||
next2(): Promise<T> | Promise<AsyncEnumeratorDone>;
|
||||
next3(): Promise<T | {}>;
|
||||
next4(): Promise<T | { x: string }>;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const x: IAsyncEnumerator<number> = null;
|
||||
let a = await x.next1();
|
||||
let b = await x.next2();
|
||||
let c = await x.next3();
|
||||
let d = await x.next4();
|
||||
}
|
||||
|
||||
//// [awaitUnionPromise.js]
|
||||
/// @target: es2015
|
||||
// https://github.com/Microsoft/TypeScript/issues/18186
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [0, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
var AsyncEnumeratorDone = /** @class */ (function () {
|
||||
function AsyncEnumeratorDone() {
|
||||
}
|
||||
return AsyncEnumeratorDone;
|
||||
}());
|
||||
;
|
||||
function main() {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var x, a, b, c, d;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
x = null;
|
||||
return [4 /*yield*/, x.next1()];
|
||||
case 1:
|
||||
a = _a.sent();
|
||||
return [4 /*yield*/, x.next2()];
|
||||
case 2:
|
||||
b = _a.sent();
|
||||
return [4 /*yield*/, x.next3()];
|
||||
case 3:
|
||||
c = _a.sent();
|
||||
return [4 /*yield*/, x.next4()];
|
||||
case 4:
|
||||
d = _a.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
=== tests/cases/compiler/awaitUnionPromise.ts ===
|
||||
/// @target: es2015
|
||||
// https://github.com/Microsoft/TypeScript/issues/18186
|
||||
|
||||
class AsyncEnumeratorDone { };
|
||||
>AsyncEnumeratorDone : Symbol(AsyncEnumeratorDone, Decl(awaitUnionPromise.ts, 0, 0))
|
||||
|
||||
interface IAsyncEnumerator<T> {
|
||||
>IAsyncEnumerator : Symbol(IAsyncEnumerator, Decl(awaitUnionPromise.ts, 3, 30))
|
||||
>T : Symbol(T, Decl(awaitUnionPromise.ts, 5, 27))
|
||||
|
||||
next1(): Promise<T | AsyncEnumeratorDone>;
|
||||
>next1 : Symbol(IAsyncEnumerator.next1, Decl(awaitUnionPromise.ts, 5, 31))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(awaitUnionPromise.ts, 5, 27))
|
||||
>AsyncEnumeratorDone : Symbol(AsyncEnumeratorDone, Decl(awaitUnionPromise.ts, 0, 0))
|
||||
|
||||
next2(): Promise<T> | Promise<AsyncEnumeratorDone>;
|
||||
>next2 : Symbol(IAsyncEnumerator.next2, Decl(awaitUnionPromise.ts, 6, 46))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(awaitUnionPromise.ts, 5, 27))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))
|
||||
>AsyncEnumeratorDone : Symbol(AsyncEnumeratorDone, Decl(awaitUnionPromise.ts, 0, 0))
|
||||
|
||||
next3(): Promise<T | {}>;
|
||||
>next3 : Symbol(IAsyncEnumerator.next3, Decl(awaitUnionPromise.ts, 7, 55))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(awaitUnionPromise.ts, 5, 27))
|
||||
|
||||
next4(): Promise<T | { x: string }>;
|
||||
>next4 : Symbol(IAsyncEnumerator.next4, Decl(awaitUnionPromise.ts, 8, 29))
|
||||
>Promise : Symbol(Promise, Decl(lib.d.ts, --, --))
|
||||
>T : Symbol(T, Decl(awaitUnionPromise.ts, 5, 27))
|
||||
>x : Symbol(x, Decl(awaitUnionPromise.ts, 9, 26))
|
||||
}
|
||||
|
||||
async function main() {
|
||||
>main : Symbol(main, Decl(awaitUnionPromise.ts, 10, 1))
|
||||
|
||||
const x: IAsyncEnumerator<number> = null;
|
||||
>x : Symbol(x, Decl(awaitUnionPromise.ts, 13, 9))
|
||||
>IAsyncEnumerator : Symbol(IAsyncEnumerator, Decl(awaitUnionPromise.ts, 3, 30))
|
||||
|
||||
let a = await x.next1();
|
||||
>a : Symbol(a, Decl(awaitUnionPromise.ts, 14, 7))
|
||||
>x.next1 : Symbol(IAsyncEnumerator.next1, Decl(awaitUnionPromise.ts, 5, 31))
|
||||
>x : Symbol(x, Decl(awaitUnionPromise.ts, 13, 9))
|
||||
>next1 : Symbol(IAsyncEnumerator.next1, Decl(awaitUnionPromise.ts, 5, 31))
|
||||
|
||||
let b = await x.next2();
|
||||
>b : Symbol(b, Decl(awaitUnionPromise.ts, 15, 7))
|
||||
>x.next2 : Symbol(IAsyncEnumerator.next2, Decl(awaitUnionPromise.ts, 6, 46))
|
||||
>x : Symbol(x, Decl(awaitUnionPromise.ts, 13, 9))
|
||||
>next2 : Symbol(IAsyncEnumerator.next2, Decl(awaitUnionPromise.ts, 6, 46))
|
||||
|
||||
let c = await x.next3();
|
||||
>c : Symbol(c, Decl(awaitUnionPromise.ts, 16, 7))
|
||||
>x.next3 : Symbol(IAsyncEnumerator.next3, Decl(awaitUnionPromise.ts, 7, 55))
|
||||
>x : Symbol(x, Decl(awaitUnionPromise.ts, 13, 9))
|
||||
>next3 : Symbol(IAsyncEnumerator.next3, Decl(awaitUnionPromise.ts, 7, 55))
|
||||
|
||||
let d = await x.next4();
|
||||
>d : Symbol(d, Decl(awaitUnionPromise.ts, 17, 7))
|
||||
>x.next4 : Symbol(IAsyncEnumerator.next4, Decl(awaitUnionPromise.ts, 8, 29))
|
||||
>x : Symbol(x, Decl(awaitUnionPromise.ts, 13, 9))
|
||||
>next4 : Symbol(IAsyncEnumerator.next4, Decl(awaitUnionPromise.ts, 8, 29))
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
=== tests/cases/compiler/awaitUnionPromise.ts ===
|
||||
/// @target: es2015
|
||||
// https://github.com/Microsoft/TypeScript/issues/18186
|
||||
|
||||
class AsyncEnumeratorDone { };
|
||||
>AsyncEnumeratorDone : AsyncEnumeratorDone
|
||||
|
||||
interface IAsyncEnumerator<T> {
|
||||
>IAsyncEnumerator : IAsyncEnumerator<T>
|
||||
>T : T
|
||||
|
||||
next1(): Promise<T | AsyncEnumeratorDone>;
|
||||
>next1 : () => Promise<AsyncEnumeratorDone | T>
|
||||
>Promise : Promise<T>
|
||||
>T : T
|
||||
>AsyncEnumeratorDone : AsyncEnumeratorDone
|
||||
|
||||
next2(): Promise<T> | Promise<AsyncEnumeratorDone>;
|
||||
>next2 : () => Promise<T> | Promise<AsyncEnumeratorDone>
|
||||
>Promise : Promise<T>
|
||||
>T : T
|
||||
>Promise : Promise<T>
|
||||
>AsyncEnumeratorDone : AsyncEnumeratorDone
|
||||
|
||||
next3(): Promise<T | {}>;
|
||||
>next3 : () => Promise<{} | T>
|
||||
>Promise : Promise<T>
|
||||
>T : T
|
||||
|
||||
next4(): Promise<T | { x: string }>;
|
||||
>next4 : () => Promise<T | { x: string; }>
|
||||
>Promise : Promise<T>
|
||||
>T : T
|
||||
>x : string
|
||||
}
|
||||
|
||||
async function main() {
|
||||
>main : () => Promise<void>
|
||||
|
||||
const x: IAsyncEnumerator<number> = null;
|
||||
>x : IAsyncEnumerator<number>
|
||||
>IAsyncEnumerator : IAsyncEnumerator<T>
|
||||
>null : null
|
||||
|
||||
let a = await x.next1();
|
||||
>a : number | AsyncEnumeratorDone
|
||||
>await x.next1() : number | AsyncEnumeratorDone
|
||||
>x.next1() : Promise<number | AsyncEnumeratorDone>
|
||||
>x.next1 : () => Promise<number | AsyncEnumeratorDone>
|
||||
>x : IAsyncEnumerator<number>
|
||||
>next1 : () => Promise<number | AsyncEnumeratorDone>
|
||||
|
||||
let b = await x.next2();
|
||||
>b : number | AsyncEnumeratorDone
|
||||
>await x.next2() : number | AsyncEnumeratorDone
|
||||
>x.next2() : Promise<AsyncEnumeratorDone> | Promise<number>
|
||||
>x.next2 : () => Promise<AsyncEnumeratorDone> | Promise<number>
|
||||
>x : IAsyncEnumerator<number>
|
||||
>next2 : () => Promise<AsyncEnumeratorDone> | Promise<number>
|
||||
|
||||
let c = await x.next3();
|
||||
>c : number | {}
|
||||
>await x.next3() : number | {}
|
||||
>x.next3() : Promise<number | {}>
|
||||
>x.next3 : () => Promise<number | {}>
|
||||
>x : IAsyncEnumerator<number>
|
||||
>next3 : () => Promise<number | {}>
|
||||
|
||||
let d = await x.next4();
|
||||
>d : number | { x: string; }
|
||||
>await x.next4() : number | { x: string; }
|
||||
>x.next4() : Promise<number | { x: string; }>
|
||||
>x.next4 : () => Promise<number | { x: string; }>
|
||||
>x : IAsyncEnumerator<number>
|
||||
>next4 : () => Promise<number | { x: string; }>
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
//// [declarationNoDanglingGenerics.ts]
|
||||
const kindCache: { [kind: string]: boolean } = {};
|
||||
|
||||
function register(kind: string): void | never {
|
||||
if (kindCache[kind]) {
|
||||
throw new Error(`Class with kind "${kind}" is already registered.`);
|
||||
}
|
||||
kindCache[kind] = true;
|
||||
}
|
||||
|
||||
function ClassFactory<TKind extends string>(kind: TKind) {
|
||||
register(kind);
|
||||
|
||||
return class {
|
||||
static readonly THE_KIND: TKind = kind;
|
||||
readonly kind: TKind = kind;
|
||||
};
|
||||
}
|
||||
|
||||
class Kinds {
|
||||
static readonly A = "A";
|
||||
static readonly B = "B";
|
||||
static readonly C = "C";
|
||||
}
|
||||
|
||||
export class AKind extends ClassFactory(Kinds.A) {
|
||||
}
|
||||
|
||||
export class BKind extends ClassFactory(Kinds.B) {
|
||||
}
|
||||
|
||||
export class CKind extends ClassFactory(Kinds.C) {
|
||||
}
|
||||
|
||||
//// [declarationNoDanglingGenerics.js]
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var 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 function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
exports.__esModule = true;
|
||||
var kindCache = {};
|
||||
function register(kind) {
|
||||
if (kindCache[kind]) {
|
||||
throw new Error("Class with kind \"" + kind + "\" is already registered.");
|
||||
}
|
||||
kindCache[kind] = true;
|
||||
}
|
||||
function ClassFactory(kind) {
|
||||
register(kind);
|
||||
return _a = /** @class */ (function () {
|
||||
function class_1() {
|
||||
this.kind = kind;
|
||||
}
|
||||
return class_1;
|
||||
}()),
|
||||
_a.THE_KIND = kind,
|
||||
_a;
|
||||
var _a;
|
||||
}
|
||||
var Kinds = /** @class */ (function () {
|
||||
function Kinds() {
|
||||
}
|
||||
Kinds.A = "A";
|
||||
Kinds.B = "B";
|
||||
Kinds.C = "C";
|
||||
return Kinds;
|
||||
}());
|
||||
var AKind = /** @class */ (function (_super) {
|
||||
__extends(AKind, _super);
|
||||
function AKind() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return AKind;
|
||||
}(ClassFactory(Kinds.A)));
|
||||
exports.AKind = AKind;
|
||||
var BKind = /** @class */ (function (_super) {
|
||||
__extends(BKind, _super);
|
||||
function BKind() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return BKind;
|
||||
}(ClassFactory(Kinds.B)));
|
||||
exports.BKind = BKind;
|
||||
var CKind = /** @class */ (function (_super) {
|
||||
__extends(CKind, _super);
|
||||
function CKind() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
return CKind;
|
||||
}(ClassFactory(Kinds.C)));
|
||||
exports.CKind = CKind;
|
||||
|
||||
|
||||
//// [declarationNoDanglingGenerics.d.ts]
|
||||
declare const AKind_base: {
|
||||
new (): {
|
||||
readonly kind: "A";
|
||||
};
|
||||
readonly THE_KIND: "A";
|
||||
};
|
||||
export declare class AKind extends AKind_base {
|
||||
}
|
||||
declare const BKind_base: {
|
||||
new (): {
|
||||
readonly kind: "B";
|
||||
};
|
||||
readonly THE_KIND: "B";
|
||||
};
|
||||
export declare class BKind extends BKind_base {
|
||||
}
|
||||
declare const CKind_base: {
|
||||
new (): {
|
||||
readonly kind: "C";
|
||||
};
|
||||
readonly THE_KIND: "C";
|
||||
};
|
||||
export declare class CKind extends CKind_base {
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
=== tests/cases/compiler/declarationNoDanglingGenerics.ts ===
|
||||
const kindCache: { [kind: string]: boolean } = {};
|
||||
>kindCache : Symbol(kindCache, Decl(declarationNoDanglingGenerics.ts, 0, 5))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 0, 20))
|
||||
|
||||
function register(kind: string): void | never {
|
||||
>register : Symbol(register, Decl(declarationNoDanglingGenerics.ts, 0, 50))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 2, 18))
|
||||
|
||||
if (kindCache[kind]) {
|
||||
>kindCache : Symbol(kindCache, Decl(declarationNoDanglingGenerics.ts, 0, 5))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 2, 18))
|
||||
|
||||
throw new Error(`Class with kind "${kind}" is already registered.`);
|
||||
>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 2, 18))
|
||||
}
|
||||
kindCache[kind] = true;
|
||||
>kindCache : Symbol(kindCache, Decl(declarationNoDanglingGenerics.ts, 0, 5))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 2, 18))
|
||||
}
|
||||
|
||||
function ClassFactory<TKind extends string>(kind: TKind) {
|
||||
>ClassFactory : Symbol(ClassFactory, Decl(declarationNoDanglingGenerics.ts, 7, 1))
|
||||
>TKind : Symbol(TKind, Decl(declarationNoDanglingGenerics.ts, 9, 22))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 9, 44))
|
||||
>TKind : Symbol(TKind, Decl(declarationNoDanglingGenerics.ts, 9, 22))
|
||||
|
||||
register(kind);
|
||||
>register : Symbol(register, Decl(declarationNoDanglingGenerics.ts, 0, 50))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 9, 44))
|
||||
|
||||
return class {
|
||||
static readonly THE_KIND: TKind = kind;
|
||||
>THE_KIND : Symbol((Anonymous class).THE_KIND, Decl(declarationNoDanglingGenerics.ts, 12, 16))
|
||||
>TKind : Symbol(TKind, Decl(declarationNoDanglingGenerics.ts, 9, 22))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 9, 44))
|
||||
|
||||
readonly kind: TKind = kind;
|
||||
>kind : Symbol((Anonymous class).kind, Decl(declarationNoDanglingGenerics.ts, 13, 43))
|
||||
>TKind : Symbol(TKind, Decl(declarationNoDanglingGenerics.ts, 9, 22))
|
||||
>kind : Symbol(kind, Decl(declarationNoDanglingGenerics.ts, 9, 44))
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
class Kinds {
|
||||
>Kinds : Symbol(Kinds, Decl(declarationNoDanglingGenerics.ts, 16, 1))
|
||||
|
||||
static readonly A = "A";
|
||||
>A : Symbol(Kinds.A, Decl(declarationNoDanglingGenerics.ts, 18, 13))
|
||||
|
||||
static readonly B = "B";
|
||||
>B : Symbol(Kinds.B, Decl(declarationNoDanglingGenerics.ts, 19, 26))
|
||||
|
||||
static readonly C = "C";
|
||||
>C : Symbol(Kinds.C, Decl(declarationNoDanglingGenerics.ts, 20, 26))
|
||||
}
|
||||
|
||||
export class AKind extends ClassFactory(Kinds.A) {
|
||||
>AKind : Symbol(AKind, Decl(declarationNoDanglingGenerics.ts, 22, 1))
|
||||
>ClassFactory : Symbol(ClassFactory, Decl(declarationNoDanglingGenerics.ts, 7, 1))
|
||||
>Kinds.A : Symbol(Kinds.A, Decl(declarationNoDanglingGenerics.ts, 18, 13))
|
||||
>Kinds : Symbol(Kinds, Decl(declarationNoDanglingGenerics.ts, 16, 1))
|
||||
>A : Symbol(Kinds.A, Decl(declarationNoDanglingGenerics.ts, 18, 13))
|
||||
}
|
||||
|
||||
export class BKind extends ClassFactory(Kinds.B) {
|
||||
>BKind : Symbol(BKind, Decl(declarationNoDanglingGenerics.ts, 25, 1))
|
||||
>ClassFactory : Symbol(ClassFactory, Decl(declarationNoDanglingGenerics.ts, 7, 1))
|
||||
>Kinds.B : Symbol(Kinds.B, Decl(declarationNoDanglingGenerics.ts, 19, 26))
|
||||
>Kinds : Symbol(Kinds, Decl(declarationNoDanglingGenerics.ts, 16, 1))
|
||||
>B : Symbol(Kinds.B, Decl(declarationNoDanglingGenerics.ts, 19, 26))
|
||||
}
|
||||
|
||||
export class CKind extends ClassFactory(Kinds.C) {
|
||||
>CKind : Symbol(CKind, Decl(declarationNoDanglingGenerics.ts, 28, 1))
|
||||
>ClassFactory : Symbol(ClassFactory, Decl(declarationNoDanglingGenerics.ts, 7, 1))
|
||||
>Kinds.C : Symbol(Kinds.C, Decl(declarationNoDanglingGenerics.ts, 20, 26))
|
||||
>Kinds : Symbol(Kinds, Decl(declarationNoDanglingGenerics.ts, 16, 1))
|
||||
>C : Symbol(Kinds.C, Decl(declarationNoDanglingGenerics.ts, 20, 26))
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
=== tests/cases/compiler/declarationNoDanglingGenerics.ts ===
|
||||
const kindCache: { [kind: string]: boolean } = {};
|
||||
>kindCache : { [kind: string]: boolean; }
|
||||
>kind : string
|
||||
>{} : {}
|
||||
|
||||
function register(kind: string): void | never {
|
||||
>register : (kind: string) => void
|
||||
>kind : string
|
||||
|
||||
if (kindCache[kind]) {
|
||||
>kindCache[kind] : boolean
|
||||
>kindCache : { [kind: string]: boolean; }
|
||||
>kind : string
|
||||
|
||||
throw new Error(`Class with kind "${kind}" is already registered.`);
|
||||
>new Error(`Class with kind "${kind}" is already registered.`) : Error
|
||||
>Error : ErrorConstructor
|
||||
>`Class with kind "${kind}" is already registered.` : string
|
||||
>kind : string
|
||||
}
|
||||
kindCache[kind] = true;
|
||||
>kindCache[kind] = true : true
|
||||
>kindCache[kind] : boolean
|
||||
>kindCache : { [kind: string]: boolean; }
|
||||
>kind : string
|
||||
>true : true
|
||||
}
|
||||
|
||||
function ClassFactory<TKind extends string>(kind: TKind) {
|
||||
>ClassFactory : <TKind extends string>(kind: TKind) => typeof (Anonymous class)
|
||||
>TKind : TKind
|
||||
>kind : TKind
|
||||
>TKind : TKind
|
||||
|
||||
register(kind);
|
||||
>register(kind) : void
|
||||
>register : (kind: string) => void
|
||||
>kind : TKind
|
||||
|
||||
return class {
|
||||
>class { static readonly THE_KIND: TKind = kind; readonly kind: TKind = kind; } : typeof (Anonymous class)
|
||||
|
||||
static readonly THE_KIND: TKind = kind;
|
||||
>THE_KIND : TKind
|
||||
>TKind : TKind
|
||||
>kind : TKind
|
||||
|
||||
readonly kind: TKind = kind;
|
||||
>kind : TKind
|
||||
>TKind : TKind
|
||||
>kind : TKind
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
class Kinds {
|
||||
>Kinds : Kinds
|
||||
|
||||
static readonly A = "A";
|
||||
>A : "A"
|
||||
>"A" : "A"
|
||||
|
||||
static readonly B = "B";
|
||||
>B : "B"
|
||||
>"B" : "B"
|
||||
|
||||
static readonly C = "C";
|
||||
>C : "C"
|
||||
>"C" : "C"
|
||||
}
|
||||
|
||||
export class AKind extends ClassFactory(Kinds.A) {
|
||||
>AKind : AKind
|
||||
>ClassFactory(Kinds.A) : ClassFactory<"A">.(Anonymous class)
|
||||
>ClassFactory : <TKind extends string>(kind: TKind) => typeof (Anonymous class)
|
||||
>Kinds.A : "A"
|
||||
>Kinds : typeof Kinds
|
||||
>A : "A"
|
||||
}
|
||||
|
||||
export class BKind extends ClassFactory(Kinds.B) {
|
||||
>BKind : BKind
|
||||
>ClassFactory(Kinds.B) : ClassFactory<"B">.(Anonymous class)
|
||||
>ClassFactory : <TKind extends string>(kind: TKind) => typeof (Anonymous class)
|
||||
>Kinds.B : "B"
|
||||
>Kinds : typeof Kinds
|
||||
>B : "B"
|
||||
}
|
||||
|
||||
export class CKind extends ClassFactory(Kinds.C) {
|
||||
>CKind : CKind
|
||||
>ClassFactory(Kinds.C) : ClassFactory<"C">.(Anonymous class)
|
||||
>ClassFactory : <TKind extends string>(kind: TKind) => typeof (Anonymous class)
|
||||
>Kinds.C : "C"
|
||||
>Kinds : typeof Kinds
|
||||
>C : "C"
|
||||
}
|
||||
@@ -83,8 +83,8 @@ var C = /** @class */ (function () {
|
||||
function id(x) {
|
||||
return x;
|
||||
}
|
||||
exports.result = id(_a || (_a = tslib_1.__makeTemplateObject(["hello world"], ["hello world"])));
|
||||
var _a;
|
||||
exports.result = id(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["hello world"], ["hello world"])));
|
||||
var templateObject_1;
|
||||
//// [script.js]
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = Object.setPrototypeOf ||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
tests/cases/conformance/types/mapped/mappedTypeWithAny.ts(23,16): error TS2339: Property 'notAValue' does not exist on type 'Data'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/mapped/mappedTypeWithAny.ts (1 errors) ====
|
||||
type Item = { value: string };
|
||||
type ItemMap<T> = { [P in keyof T]: Item };
|
||||
|
||||
declare let x0: keyof any;
|
||||
declare let x1: { [P in any]: Item };
|
||||
declare let x2: { [P in string]: Item };
|
||||
declare let x3: { [P in keyof any]: Item };
|
||||
declare let x4: ItemMap<any>;
|
||||
|
||||
// Repro from #19152
|
||||
|
||||
type Data = {
|
||||
value: string;
|
||||
}
|
||||
|
||||
type StrictDataMap<T> = {
|
||||
[P in keyof T]: Data
|
||||
}
|
||||
|
||||
declare let z: StrictDataMap<any>;
|
||||
for (let id in z) {
|
||||
let data = z[id];
|
||||
let x = data.notAValue; // Error
|
||||
~~~~~~~~~
|
||||
!!! error TS2339: Property 'notAValue' does not exist on type 'Data'.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
//// [mappedTypeWithAny.ts]
|
||||
type Item = { value: string };
|
||||
type ItemMap<T> = { [P in keyof T]: Item };
|
||||
|
||||
declare let x0: keyof any;
|
||||
declare let x1: { [P in any]: Item };
|
||||
declare let x2: { [P in string]: Item };
|
||||
declare let x3: { [P in keyof any]: Item };
|
||||
declare let x4: ItemMap<any>;
|
||||
|
||||
// Repro from #19152
|
||||
|
||||
type Data = {
|
||||
value: string;
|
||||
}
|
||||
|
||||
type StrictDataMap<T> = {
|
||||
[P in keyof T]: Data
|
||||
}
|
||||
|
||||
declare let z: StrictDataMap<any>;
|
||||
for (let id in z) {
|
||||
let data = z[id];
|
||||
let x = data.notAValue; // Error
|
||||
}
|
||||
|
||||
|
||||
//// [mappedTypeWithAny.js]
|
||||
"use strict";
|
||||
for (var id in z) {
|
||||
var data = z[id];
|
||||
var x = data.notAValue; // Error
|
||||
}
|
||||
|
||||
|
||||
//// [mappedTypeWithAny.d.ts]
|
||||
declare type Item = {
|
||||
value: string;
|
||||
};
|
||||
declare type ItemMap<T> = {
|
||||
[P in keyof T]: Item;
|
||||
};
|
||||
declare let x0: keyof any;
|
||||
declare let x1: {
|
||||
[P in any]: Item;
|
||||
};
|
||||
declare let x2: {
|
||||
[P in string]: Item;
|
||||
};
|
||||
declare let x3: {
|
||||
[P in keyof any]: Item;
|
||||
};
|
||||
declare let x4: ItemMap<any>;
|
||||
declare type Data = {
|
||||
value: string;
|
||||
};
|
||||
declare type StrictDataMap<T> = {
|
||||
[P in keyof T]: Data;
|
||||
};
|
||||
declare let z: StrictDataMap<any>;
|
||||
@@ -0,0 +1,71 @@
|
||||
=== tests/cases/conformance/types/mapped/mappedTypeWithAny.ts ===
|
||||
type Item = { value: string };
|
||||
>Item : Symbol(Item, Decl(mappedTypeWithAny.ts, 0, 0))
|
||||
>value : Symbol(value, Decl(mappedTypeWithAny.ts, 0, 13))
|
||||
|
||||
type ItemMap<T> = { [P in keyof T]: Item };
|
||||
>ItemMap : Symbol(ItemMap, Decl(mappedTypeWithAny.ts, 0, 30))
|
||||
>T : Symbol(T, Decl(mappedTypeWithAny.ts, 1, 13))
|
||||
>P : Symbol(P, Decl(mappedTypeWithAny.ts, 1, 21))
|
||||
>T : Symbol(T, Decl(mappedTypeWithAny.ts, 1, 13))
|
||||
>Item : Symbol(Item, Decl(mappedTypeWithAny.ts, 0, 0))
|
||||
|
||||
declare let x0: keyof any;
|
||||
>x0 : Symbol(x0, Decl(mappedTypeWithAny.ts, 3, 11))
|
||||
|
||||
declare let x1: { [P in any]: Item };
|
||||
>x1 : Symbol(x1, Decl(mappedTypeWithAny.ts, 4, 11))
|
||||
>P : Symbol(P, Decl(mappedTypeWithAny.ts, 4, 19))
|
||||
>Item : Symbol(Item, Decl(mappedTypeWithAny.ts, 0, 0))
|
||||
|
||||
declare let x2: { [P in string]: Item };
|
||||
>x2 : Symbol(x2, Decl(mappedTypeWithAny.ts, 5, 11))
|
||||
>P : Symbol(P, Decl(mappedTypeWithAny.ts, 5, 19))
|
||||
>Item : Symbol(Item, Decl(mappedTypeWithAny.ts, 0, 0))
|
||||
|
||||
declare let x3: { [P in keyof any]: Item };
|
||||
>x3 : Symbol(x3, Decl(mappedTypeWithAny.ts, 6, 11))
|
||||
>P : Symbol(P, Decl(mappedTypeWithAny.ts, 6, 19))
|
||||
>Item : Symbol(Item, Decl(mappedTypeWithAny.ts, 0, 0))
|
||||
|
||||
declare let x4: ItemMap<any>;
|
||||
>x4 : Symbol(x4, Decl(mappedTypeWithAny.ts, 7, 11))
|
||||
>ItemMap : Symbol(ItemMap, Decl(mappedTypeWithAny.ts, 0, 30))
|
||||
|
||||
// Repro from #19152
|
||||
|
||||
type Data = {
|
||||
>Data : Symbol(Data, Decl(mappedTypeWithAny.ts, 7, 29))
|
||||
|
||||
value: string;
|
||||
>value : Symbol(value, Decl(mappedTypeWithAny.ts, 11, 13))
|
||||
}
|
||||
|
||||
type StrictDataMap<T> = {
|
||||
>StrictDataMap : Symbol(StrictDataMap, Decl(mappedTypeWithAny.ts, 13, 1))
|
||||
>T : Symbol(T, Decl(mappedTypeWithAny.ts, 15, 19))
|
||||
|
||||
[P in keyof T]: Data
|
||||
>P : Symbol(P, Decl(mappedTypeWithAny.ts, 16, 3))
|
||||
>T : Symbol(T, Decl(mappedTypeWithAny.ts, 15, 19))
|
||||
>Data : Symbol(Data, Decl(mappedTypeWithAny.ts, 7, 29))
|
||||
}
|
||||
|
||||
declare let z: StrictDataMap<any>;
|
||||
>z : Symbol(z, Decl(mappedTypeWithAny.ts, 19, 11))
|
||||
>StrictDataMap : Symbol(StrictDataMap, Decl(mappedTypeWithAny.ts, 13, 1))
|
||||
|
||||
for (let id in z) {
|
||||
>id : Symbol(id, Decl(mappedTypeWithAny.ts, 20, 8))
|
||||
>z : Symbol(z, Decl(mappedTypeWithAny.ts, 19, 11))
|
||||
|
||||
let data = z[id];
|
||||
>data : Symbol(data, Decl(mappedTypeWithAny.ts, 21, 5))
|
||||
>z : Symbol(z, Decl(mappedTypeWithAny.ts, 19, 11))
|
||||
>id : Symbol(id, Decl(mappedTypeWithAny.ts, 20, 8))
|
||||
|
||||
let x = data.notAValue; // Error
|
||||
>x : Symbol(x, Decl(mappedTypeWithAny.ts, 22, 5))
|
||||
>data : Symbol(data, Decl(mappedTypeWithAny.ts, 21, 5))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
=== tests/cases/conformance/types/mapped/mappedTypeWithAny.ts ===
|
||||
type Item = { value: string };
|
||||
>Item : Item
|
||||
>value : string
|
||||
|
||||
type ItemMap<T> = { [P in keyof T]: Item };
|
||||
>ItemMap : ItemMap<T>
|
||||
>T : T
|
||||
>P : P
|
||||
>T : T
|
||||
>Item : Item
|
||||
|
||||
declare let x0: keyof any;
|
||||
>x0 : string
|
||||
|
||||
declare let x1: { [P in any]: Item };
|
||||
>x1 : { [x: string]: Item; }
|
||||
>P : P
|
||||
>Item : Item
|
||||
|
||||
declare let x2: { [P in string]: Item };
|
||||
>x2 : { [x: string]: Item; }
|
||||
>P : P
|
||||
>Item : Item
|
||||
|
||||
declare let x3: { [P in keyof any]: Item };
|
||||
>x3 : { [x: string]: Item; }
|
||||
>P : P
|
||||
>Item : Item
|
||||
|
||||
declare let x4: ItemMap<any>;
|
||||
>x4 : ItemMap<any>
|
||||
>ItemMap : ItemMap<T>
|
||||
|
||||
// Repro from #19152
|
||||
|
||||
type Data = {
|
||||
>Data : Data
|
||||
|
||||
value: string;
|
||||
>value : string
|
||||
}
|
||||
|
||||
type StrictDataMap<T> = {
|
||||
>StrictDataMap : StrictDataMap<T>
|
||||
>T : T
|
||||
|
||||
[P in keyof T]: Data
|
||||
>P : P
|
||||
>T : T
|
||||
>Data : Data
|
||||
}
|
||||
|
||||
declare let z: StrictDataMap<any>;
|
||||
>z : StrictDataMap<any>
|
||||
>StrictDataMap : StrictDataMap<T>
|
||||
|
||||
for (let id in z) {
|
||||
>id : string
|
||||
>z : StrictDataMap<any>
|
||||
|
||||
let data = z[id];
|
||||
>data : Data
|
||||
>z[id] : Data
|
||||
>z : StrictDataMap<any>
|
||||
>id : string
|
||||
|
||||
let x = data.notAValue; // Error
|
||||
>x : any
|
||||
>data.notAValue : any
|
||||
>data : Data
|
||||
>notAValue : any
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/compiler/moduleResolution_packageJson_notAtPackageRoot.ts] ////
|
||||
|
||||
//// [package.json]
|
||||
// Loads from a "fake" nested package.json, not from the one at the root.
|
||||
|
||||
{ "types": "types.d.ts" }
|
||||
|
||||
//// [package.json]
|
||||
{}
|
||||
|
||||
//// [types.d.ts]
|
||||
export const x: number;
|
||||
|
||||
//// [a.ts]
|
||||
import { x } from "foo/bar";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
@@ -0,0 +1,8 @@
|
||||
=== /a.ts ===
|
||||
import { x } from "foo/bar";
|
||||
>x : Symbol(x, Decl(a.ts, 0, 8))
|
||||
|
||||
=== /node_modules/foo/bar/types.d.ts ===
|
||||
export const x: number;
|
||||
>x : Symbol(x, Decl(types.d.ts, 0, 12))
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
[
|
||||
"======== Resolving module 'foo/bar' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'foo/bar' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Found 'package.json' at '/node_modules/foo/bar/package.json'.",
|
||||
"File '/node_modules/foo/bar.ts' does not exist.",
|
||||
"File '/node_modules/foo/bar.tsx' does not exist.",
|
||||
"File '/node_modules/foo/bar.d.ts' does not exist.",
|
||||
"'package.json' does not have a 'typings' field.",
|
||||
"'package.json' has 'types' field 'types.d.ts' that references '/node_modules/foo/bar/types.d.ts'.",
|
||||
"File '/node_modules/foo/bar/types.d.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/foo/bar/types.d.ts', result '/node_modules/foo/bar/types.d.ts'.",
|
||||
"======== Module name 'foo/bar' was successfully resolved to '/node_modules/foo/bar/types.d.ts'. ========"
|
||||
]
|
||||
@@ -0,0 +1,8 @@
|
||||
=== /a.ts ===
|
||||
import { x } from "foo/bar";
|
||||
>x : number
|
||||
|
||||
=== /node_modules/foo/bar/types.d.ts ===
|
||||
export const x: number;
|
||||
>x : number
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/compiler/moduleResolution_packageJson_notAtPackageRoot_fakeScopedPackage.ts] ////
|
||||
|
||||
//// [package.json]
|
||||
// Copy of `moduleResolution_packageJson_notAtPackageRoot` with `foo/@bar` instead of `foo/bar`. Should behave identically.
|
||||
|
||||
{ "types": "types.d.ts" }
|
||||
|
||||
//// [package.json]
|
||||
{}
|
||||
|
||||
//// [types.d.ts]
|
||||
export const x: number;
|
||||
|
||||
//// [a.ts]
|
||||
import { x } from "foo/@bar";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
=== /a.ts ===
|
||||
import { x } from "foo/@bar";
|
||||
>x : Symbol(x, Decl(a.ts, 0, 8))
|
||||
|
||||
=== /node_modules/foo/@bar/types.d.ts ===
|
||||
export const x: number;
|
||||
>x : Symbol(x, Decl(types.d.ts, 0, 12))
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
[
|
||||
"======== Resolving module 'foo/@bar' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'foo/@bar' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"Found 'package.json' at '/node_modules/foo/@bar/package.json'.",
|
||||
"File '/node_modules/foo/@bar.ts' does not exist.",
|
||||
"File '/node_modules/foo/@bar.tsx' does not exist.",
|
||||
"File '/node_modules/foo/@bar.d.ts' does not exist.",
|
||||
"'package.json' does not have a 'typings' field.",
|
||||
"'package.json' has 'types' field 'types.d.ts' that references '/node_modules/foo/@bar/types.d.ts'.",
|
||||
"File '/node_modules/foo/@bar/types.d.ts' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/foo/@bar/types.d.ts', result '/node_modules/foo/@bar/types.d.ts'.",
|
||||
"======== Module name 'foo/@bar' was successfully resolved to '/node_modules/foo/@bar/types.d.ts'. ========"
|
||||
]
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
=== /a.ts ===
|
||||
import { x } from "foo/@bar";
|
||||
>x : number
|
||||
|
||||
=== /node_modules/foo/@bar/types.d.ts ===
|
||||
export const x: number;
|
||||
>x : number
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//// [tests/cases/compiler/moduleResolution_packageJson_yesAtPackageRoot.ts] ////
|
||||
|
||||
//// [index.js]
|
||||
not read
|
||||
|
||||
//// [package.json]
|
||||
{ "name": "foo", "version": "1.2.3", "types": "types.d.ts" }
|
||||
|
||||
//// [types.d.ts]
|
||||
export const x = 0;
|
||||
|
||||
//// [a.ts]
|
||||
import { x } from "foo/bar";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
@@ -0,0 +1,4 @@
|
||||
=== /a.ts ===
|
||||
import { x } from "foo/bar";
|
||||
>x : Symbol(x, Decl(a.ts, 0, 8))
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
[
|
||||
"======== Resolving module 'foo/bar' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'foo/bar' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"File '/node_modules/foo/bar/package.json' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/foo/package.json'.",
|
||||
"File '/node_modules/foo/bar.ts' does not exist.",
|
||||
"File '/node_modules/foo/bar.tsx' does not exist.",
|
||||
"File '/node_modules/foo/bar.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/bar/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/bar/index.tsx' does not exist.",
|
||||
"File '/node_modules/foo/bar/index.d.ts' does not exist.",
|
||||
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
|
||||
"Loading module 'foo/bar' from 'node_modules' folder, target file type 'JavaScript'.",
|
||||
"File '/node_modules/foo/bar/package.json' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/foo/package.json'.",
|
||||
"File '/node_modules/foo/bar.js' does not exist.",
|
||||
"File '/node_modules/foo/bar.jsx' does not exist.",
|
||||
"File '/node_modules/foo/bar/index.js' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/foo/bar/index.js', result '/node_modules/foo/bar/index.js'.",
|
||||
"======== Module name 'foo/bar' was successfully resolved to '/node_modules/foo/bar/index.js'. ========"
|
||||
]
|
||||
@@ -0,0 +1,4 @@
|
||||
=== /a.ts ===
|
||||
import { x } from "foo/bar";
|
||||
>x : any
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/compiler/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.ts] ////
|
||||
|
||||
//// [index.js]
|
||||
// Copy of `moduleResolution_packageJson_notAtPackageRoot` with `foo/@bar` instead of `foo/bar`. Should behave identically.
|
||||
|
||||
not read
|
||||
|
||||
//// [package.json]
|
||||
{ "name": "foo", "version": "1.2.3", "types": "types.d.ts" }
|
||||
|
||||
//// [types.d.ts]
|
||||
export const x = 0;
|
||||
|
||||
//// [a.ts]
|
||||
import { x } from "foo/@bar";
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
=== /a.ts ===
|
||||
import { x } from "foo/@bar";
|
||||
>x : Symbol(x, Decl(a.ts, 0, 8))
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
[
|
||||
"======== Resolving module 'foo/@bar' from '/a.ts'. ========",
|
||||
"Module resolution kind is not specified, using 'NodeJs'.",
|
||||
"Loading module 'foo/@bar' from 'node_modules' folder, target file type 'TypeScript'.",
|
||||
"File '/node_modules/foo/@bar/package.json' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/foo/package.json'.",
|
||||
"File '/node_modules/foo/@bar.ts' does not exist.",
|
||||
"File '/node_modules/foo/@bar.tsx' does not exist.",
|
||||
"File '/node_modules/foo/@bar.d.ts' does not exist.",
|
||||
"File '/node_modules/foo/@bar/index.ts' does not exist.",
|
||||
"File '/node_modules/foo/@bar/index.tsx' does not exist.",
|
||||
"File '/node_modules/foo/@bar/index.d.ts' does not exist.",
|
||||
"Directory '/node_modules/@types' does not exist, skipping all lookups in it.",
|
||||
"Loading module 'foo/@bar' from 'node_modules' folder, target file type 'JavaScript'.",
|
||||
"File '/node_modules/foo/@bar/package.json' does not exist.",
|
||||
"Found 'package.json' at '/node_modules/foo/package.json'.",
|
||||
"File '/node_modules/foo/@bar.js' does not exist.",
|
||||
"File '/node_modules/foo/@bar.jsx' does not exist.",
|
||||
"File '/node_modules/foo/@bar/index.js' exist - use it as a name resolution result.",
|
||||
"Resolving real path for '/node_modules/foo/@bar/index.js', result '/node_modules/foo/@bar/index.js'.",
|
||||
"======== Module name 'foo/@bar' was successfully resolved to '/node_modules/foo/@bar/index.js'. ========"
|
||||
]
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
=== /a.ts ===
|
||||
import { x } from "foo/@bar";
|
||||
>x : any
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//// [systemJsForInNoException.ts]
|
||||
export const obj = { a: 1 };
|
||||
for (var key in obj)
|
||||
console.log(obj[key]);
|
||||
|
||||
//// [systemJsForInNoException.js]
|
||||
System.register([], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var obj, key;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
exports_1("obj", obj = { a: 1 });
|
||||
for (key in obj)
|
||||
console.log(obj[key]);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/systemJsForInNoException.ts ===
|
||||
export const obj = { a: 1 };
|
||||
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
|
||||
>a : Symbol(a, Decl(systemJsForInNoException.ts, 0, 20))
|
||||
|
||||
for (var key in obj)
|
||||
>key : Symbol(key, Decl(systemJsForInNoException.ts, 1, 8))
|
||||
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
|
||||
|
||||
console.log(obj[key]);
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>obj : Symbol(obj, Decl(systemJsForInNoException.ts, 0, 12))
|
||||
>key : Symbol(key, Decl(systemJsForInNoException.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/systemJsForInNoException.ts ===
|
||||
export const obj = { a: 1 };
|
||||
>obj : { a: number; }
|
||||
>{ a: 1 } : { a: number; }
|
||||
>a : number
|
||||
>1 : 1
|
||||
|
||||
for (var key in obj)
|
||||
>key : string
|
||||
>obj : { a: number; }
|
||||
|
||||
console.log(obj[key]);
|
||||
>console.log(obj[key]) : void
|
||||
>console.log : (message?: any, ...optionalParams: any[]) => void
|
||||
>console : Console
|
||||
>log : (message?: any, ...optionalParams: any[]) => void
|
||||
>obj[key] : any
|
||||
>obj : { a: number; }
|
||||
>key : string
|
||||
|
||||
@@ -18,5 +18,5 @@ var tslib_1 = require("tslib");
|
||||
function id(x) {
|
||||
return x;
|
||||
}
|
||||
exports.result = id(_a || (_a = tslib_1.__makeTemplateObject(["hello world"], ["hello world"])));
|
||||
var _a;
|
||||
exports.result = id(templateObject_1 || (templateObject_1 = tslib_1.__makeTemplateObject(["hello world"], ["hello world"])));
|
||||
var templateObject_1;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//// [taggedTemplatesInDifferentScopes.ts]
|
||||
export function tag(parts: TemplateStringsArray, ...values: any[]) {
|
||||
return parts[0];
|
||||
}
|
||||
function foo() {
|
||||
tag `foo`;
|
||||
tag `foo2`;
|
||||
}
|
||||
|
||||
function bar() {
|
||||
tag `bar`;
|
||||
tag `bar2`;
|
||||
}
|
||||
|
||||
foo();
|
||||
bar();
|
||||
|
||||
|
||||
//// [taggedTemplatesInDifferentScopes.js]
|
||||
"use strict";
|
||||
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
|
||||
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
|
||||
return cooked;
|
||||
};
|
||||
exports.__esModule = true;
|
||||
function tag(parts) {
|
||||
var values = [];
|
||||
for (var _i = 1; _i < arguments.length; _i++) {
|
||||
values[_i - 1] = arguments[_i];
|
||||
}
|
||||
return parts[0];
|
||||
}
|
||||
exports.tag = tag;
|
||||
function foo() {
|
||||
tag(templateObject_1 || (templateObject_1 = __makeTemplateObject(["foo"], ["foo"])));
|
||||
tag(templateObject_2 || (templateObject_2 = __makeTemplateObject(["foo2"], ["foo2"])));
|
||||
}
|
||||
function bar() {
|
||||
tag(templateObject_3 || (templateObject_3 = __makeTemplateObject(["bar"], ["bar"])));
|
||||
tag(templateObject_4 || (templateObject_4 = __makeTemplateObject(["bar2"], ["bar2"])));
|
||||
}
|
||||
foo();
|
||||
bar();
|
||||
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
|
||||
@@ -0,0 +1,36 @@
|
||||
=== tests/cases/compiler/taggedTemplatesInDifferentScopes.ts ===
|
||||
export function tag(parts: TemplateStringsArray, ...values: any[]) {
|
||||
>tag : Symbol(tag, Decl(taggedTemplatesInDifferentScopes.ts, 0, 0))
|
||||
>parts : Symbol(parts, Decl(taggedTemplatesInDifferentScopes.ts, 0, 20))
|
||||
>TemplateStringsArray : Symbol(TemplateStringsArray, Decl(lib.d.ts, --, --))
|
||||
>values : Symbol(values, Decl(taggedTemplatesInDifferentScopes.ts, 0, 48))
|
||||
|
||||
return parts[0];
|
||||
>parts : Symbol(parts, Decl(taggedTemplatesInDifferentScopes.ts, 0, 20))
|
||||
}
|
||||
function foo() {
|
||||
>foo : Symbol(foo, Decl(taggedTemplatesInDifferentScopes.ts, 2, 1))
|
||||
|
||||
tag `foo`;
|
||||
>tag : Symbol(tag, Decl(taggedTemplatesInDifferentScopes.ts, 0, 0))
|
||||
|
||||
tag `foo2`;
|
||||
>tag : Symbol(tag, Decl(taggedTemplatesInDifferentScopes.ts, 0, 0))
|
||||
}
|
||||
|
||||
function bar() {
|
||||
>bar : Symbol(bar, Decl(taggedTemplatesInDifferentScopes.ts, 6, 1))
|
||||
|
||||
tag `bar`;
|
||||
>tag : Symbol(tag, Decl(taggedTemplatesInDifferentScopes.ts, 0, 0))
|
||||
|
||||
tag `bar2`;
|
||||
>tag : Symbol(tag, Decl(taggedTemplatesInDifferentScopes.ts, 0, 0))
|
||||
}
|
||||
|
||||
foo();
|
||||
>foo : Symbol(foo, Decl(taggedTemplatesInDifferentScopes.ts, 2, 1))
|
||||
|
||||
bar();
|
||||
>bar : Symbol(bar, Decl(taggedTemplatesInDifferentScopes.ts, 6, 1))
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
=== tests/cases/compiler/taggedTemplatesInDifferentScopes.ts ===
|
||||
export function tag(parts: TemplateStringsArray, ...values: any[]) {
|
||||
>tag : (parts: TemplateStringsArray, ...values: any[]) => string
|
||||
>parts : TemplateStringsArray
|
||||
>TemplateStringsArray : TemplateStringsArray
|
||||
>values : any[]
|
||||
|
||||
return parts[0];
|
||||
>parts[0] : string
|
||||
>parts : TemplateStringsArray
|
||||
>0 : 0
|
||||
}
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
tag `foo`;
|
||||
>tag `foo` : string
|
||||
>tag : (parts: TemplateStringsArray, ...values: any[]) => string
|
||||
>`foo` : "foo"
|
||||
|
||||
tag `foo2`;
|
||||
>tag `foo2` : string
|
||||
>tag : (parts: TemplateStringsArray, ...values: any[]) => string
|
||||
>`foo2` : "foo2"
|
||||
}
|
||||
|
||||
function bar() {
|
||||
>bar : () => void
|
||||
|
||||
tag `bar`;
|
||||
>tag `bar` : string
|
||||
>tag : (parts: TemplateStringsArray, ...values: any[]) => string
|
||||
>`bar` : "bar"
|
||||
|
||||
tag `bar2`;
|
||||
>tag `bar2` : string
|
||||
>tag : (parts: TemplateStringsArray, ...values: any[]) => string
|
||||
>`bar2` : "bar2"
|
||||
}
|
||||
|
||||
foo();
|
||||
>foo() : void
|
||||
>foo : () => void
|
||||
|
||||
bar();
|
||||
>bar() : void
|
||||
>bar : () => void
|
||||
|
||||
@@ -49,7 +49,7 @@ function id(x) {
|
||||
return x;
|
||||
}
|
||||
function templateObjectFactory() {
|
||||
return id(_a || (_a = __makeTemplateObject(["hello world"], ["hello world"])));
|
||||
return id(templateObject_1 || (templateObject_1 = __makeTemplateObject(["hello world"], ["hello world"])));
|
||||
}
|
||||
var result = templateObjectFactory() === templateObjectFactory();
|
||||
var _a;
|
||||
var templateObject_1;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// @target: es5
|
||||
// @lib: es2015
|
||||
// https://github.com/Microsoft/TypeScript/issues/19187
|
||||
|
||||
async ({ foo, bar, ...rest }) => bar(await foo);
|
||||
@@ -0,0 +1,19 @@
|
||||
/// @target: es2015
|
||||
// https://github.com/Microsoft/TypeScript/issues/18186
|
||||
|
||||
class AsyncEnumeratorDone { };
|
||||
|
||||
interface IAsyncEnumerator<T> {
|
||||
next1(): Promise<T | AsyncEnumeratorDone>;
|
||||
next2(): Promise<T> | Promise<AsyncEnumeratorDone>;
|
||||
next3(): Promise<T | {}>;
|
||||
next4(): Promise<T | { x: string }>;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const x: IAsyncEnumerator<number> = null;
|
||||
let a = await x.next1();
|
||||
let b = await x.next2();
|
||||
let c = await x.next3();
|
||||
let d = await x.next4();
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// @declaration: true
|
||||
const kindCache: { [kind: string]: boolean } = {};
|
||||
|
||||
function register(kind: string): void | never {
|
||||
if (kindCache[kind]) {
|
||||
throw new Error(`Class with kind "${kind}" is already registered.`);
|
||||
}
|
||||
kindCache[kind] = true;
|
||||
}
|
||||
|
||||
function ClassFactory<TKind extends string>(kind: TKind) {
|
||||
register(kind);
|
||||
|
||||
return class {
|
||||
static readonly THE_KIND: TKind = kind;
|
||||
readonly kind: TKind = kind;
|
||||
};
|
||||
}
|
||||
|
||||
class Kinds {
|
||||
static readonly A = "A";
|
||||
static readonly B = "B";
|
||||
static readonly C = "C";
|
||||
}
|
||||
|
||||
export class AKind extends ClassFactory(Kinds.A) {
|
||||
}
|
||||
|
||||
export class BKind extends ClassFactory(Kinds.B) {
|
||||
}
|
||||
|
||||
export class CKind extends ClassFactory(Kinds.C) {
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
|
||||
// Loads from a "fake" nested package.json, not from the one at the root.
|
||||
|
||||
// @Filename: /node_modules/foo/bar/package.json
|
||||
{ "types": "types.d.ts" }
|
||||
|
||||
// @Filename: /node_modules/foo/package.json
|
||||
{}
|
||||
|
||||
// @Filename: /node_modules/foo/bar/types.d.ts
|
||||
export const x: number;
|
||||
|
||||
// @Filename: /a.ts
|
||||
import { x } from "foo/bar";
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
|
||||
// Copy of `moduleResolution_packageJson_notAtPackageRoot` with `foo/@bar` instead of `foo/bar`. Should behave identically.
|
||||
|
||||
// @Filename: /node_modules/foo/@bar/package.json
|
||||
{ "types": "types.d.ts" }
|
||||
|
||||
// @Filename: /node_modules/foo/package.json
|
||||
{}
|
||||
|
||||
// @Filename: /node_modules/foo/@bar/types.d.ts
|
||||
export const x: number;
|
||||
|
||||
// @Filename: /a.ts
|
||||
import { x } from "foo/@bar";
|
||||
@@ -0,0 +1,14 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
|
||||
// @Filename: /node_modules/foo/bar/index.js
|
||||
not read
|
||||
|
||||
// @Filename: /node_modules/foo/package.json
|
||||
{ "name": "foo", "version": "1.2.3", "types": "types.d.ts" }
|
||||
|
||||
// @Filename: /node_modules/foo/types.d.ts
|
||||
export const x = 0;
|
||||
|
||||
// @Filename: /a.ts
|
||||
import { x } from "foo/bar";
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// @noImplicitReferences: true
|
||||
// @traceResolution: true
|
||||
|
||||
// Copy of `moduleResolution_packageJson_notAtPackageRoot` with `foo/@bar` instead of `foo/bar`. Should behave identically.
|
||||
|
||||
// @Filename: /node_modules/foo/@bar/index.js
|
||||
not read
|
||||
|
||||
// @Filename: /node_modules/foo/package.json
|
||||
{ "name": "foo", "version": "1.2.3", "types": "types.d.ts" }
|
||||
|
||||
// @Filename: /node_modules/foo/types.d.ts
|
||||
export const x = 0;
|
||||
|
||||
// @Filename: /a.ts
|
||||
import { x } from "foo/@bar";
|
||||
@@ -0,0 +1,5 @@
|
||||
// @module: system
|
||||
// @lib: es6,dom
|
||||
export const obj = { a: 1 };
|
||||
for (var key in obj)
|
||||
console.log(obj[key]);
|
||||
@@ -0,0 +1,15 @@
|
||||
export function tag(parts: TemplateStringsArray, ...values: any[]) {
|
||||
return parts[0];
|
||||
}
|
||||
function foo() {
|
||||
tag `foo`;
|
||||
tag `foo2`;
|
||||
}
|
||||
|
||||
function bar() {
|
||||
tag `bar`;
|
||||
tag `bar2`;
|
||||
}
|
||||
|
||||
foo();
|
||||
bar();
|
||||
@@ -0,0 +1,27 @@
|
||||
// @strict: true
|
||||
// @declaration: true
|
||||
|
||||
type Item = { value: string };
|
||||
type ItemMap<T> = { [P in keyof T]: Item };
|
||||
|
||||
declare let x0: keyof any;
|
||||
declare let x1: { [P in any]: Item };
|
||||
declare let x2: { [P in string]: Item };
|
||||
declare let x3: { [P in keyof any]: Item };
|
||||
declare let x4: ItemMap<any>;
|
||||
|
||||
// Repro from #19152
|
||||
|
||||
type Data = {
|
||||
value: string;
|
||||
}
|
||||
|
||||
type StrictDataMap<T> = {
|
||||
[P in keyof T]: Data
|
||||
}
|
||||
|
||||
declare let z: StrictDataMap<any>;
|
||||
for (let id in z) {
|
||||
let data = z[id];
|
||||
let x = data.notAValue; // Error
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: test123.ts
|
||||
/////** @type {number} */
|
||||
////var /*1*/x;
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/** @type {number} */
|
||||
var x: number;`, 'Annotate with type from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
/////**
|
||||
//// * @param {?} x
|
||||
//// * @returns {number}
|
||||
//// */
|
||||
////var f = /*1*/(/*2*/x) => x
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/**
|
||||
* @param {?} x
|
||||
* @returns {number}
|
||||
*/
|
||||
var f = (x: any): number => x`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
/////**
|
||||
//// * @param {?} x
|
||||
//// * @returns {number}
|
||||
//// */
|
||||
////var f = /*1*/(/*2*/x) => x
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('2');
|
||||
verify.fileAfterApplyingRefactorAtMarker('2',
|
||||
`/**
|
||||
* @param {?} x
|
||||
* @returns {number}
|
||||
*/
|
||||
var f = (x: any): number => x`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////class C {
|
||||
//// /**
|
||||
//// * @return {...*}
|
||||
//// */
|
||||
//// /*1*/m(x) {
|
||||
//// }
|
||||
////}
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`class C {
|
||||
/**
|
||||
* @return {...*}
|
||||
*/
|
||||
m(x): any[] {
|
||||
}
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
////class C {
|
||||
//// /** @return {number} */
|
||||
//// get /*1*/c() { return 12 }
|
||||
////}
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`class C {
|
||||
/** @return {number} */
|
||||
get c(): number { return 12; }
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
/////** @return {number} */
|
||||
////function f() {
|
||||
//// /*1*/return 12;
|
||||
////}
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/** @return {number} */
|
||||
function f(): number {
|
||||
return 12;
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,30 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @strict: true
|
||||
/////**
|
||||
//// * @param {Boolean} x
|
||||
//// * @param {String} y
|
||||
//// * @param {Number} z
|
||||
//// * @param {Object} alpha
|
||||
//// * @param {date} beta
|
||||
//// * @param {promise} gamma
|
||||
//// * @param {array} delta
|
||||
//// * @param {Array<number>} epsilon
|
||||
//// * @param {promise<String>} zeta
|
||||
//// */
|
||||
////function f(/*1*/x, /*2*/y, /*3*/z, /*4*/alpha, /*5*/beta, /*6*/gamma, /*7*/delta, /*8*/epsilon, /*9*/zeta) {
|
||||
////}
|
||||
verify.applicableRefactorAvailableAtMarker('9');
|
||||
verify.fileAfterApplyingRefactorAtMarker('9',
|
||||
`/**
|
||||
* @param {Boolean} x
|
||||
* @param {String} y
|
||||
* @param {Number} z
|
||||
* @param {Object} alpha
|
||||
* @param {date} beta
|
||||
* @param {promise} gamma
|
||||
* @param {array} delta
|
||||
* @param {Array<number>} epsilon
|
||||
* @param {promise<String>} zeta
|
||||
*/
|
||||
function f(x: boolean, y: string, z: number, alpha: object, beta: Date, gamma: Promise<any>, delta: Array<any>, epsilon: Array<number>, zeta: Promise<string>) {
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,9 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @strict: true
|
||||
/////** @type {function(*, ...number, ...boolean): void} */
|
||||
////var /*1*/x = (x, ys, ...zs) => { };
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/** @type {function(*, ...number, ...boolean): void} */
|
||||
var x: (arg0: any, arg1: number[], ...rest: boolean[]) => void = (x, ys, ...zs) => { };`, 'Annotate with type from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
////class C {
|
||||
//// /**
|
||||
//// * @param {number} x - the first parameter
|
||||
//// */
|
||||
//// constructor(/*1*/x) {
|
||||
//// }
|
||||
////}
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`class C {
|
||||
/**
|
||||
* @param {number} x - the first parameter
|
||||
*/
|
||||
constructor(x: number) {
|
||||
}
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
////class C {
|
||||
//// /** @param {number} value */
|
||||
//// set c(/*1*/value) { return 12 }
|
||||
////}
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`class C {
|
||||
/** @param {number} value */
|
||||
set c(value: number) { return 12; }
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,19 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @strict: true
|
||||
/////**
|
||||
//// * @template T
|
||||
//// * @param {number} a
|
||||
//// * @param {T} b
|
||||
//// */
|
||||
////function /*1*/f(a, b) {
|
||||
////}
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/**
|
||||
* @template T
|
||||
* @param {number} a
|
||||
* @param {T} b
|
||||
*/
|
||||
function f<T>(a: number, b: T) {
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,6 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: test123.ts
|
||||
/////** @type {number} */
|
||||
////var /*1*/x: string;
|
||||
verify.not.applicableRefactorAvailableAtMarker('1');
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @strict: true
|
||||
/////**
|
||||
//// * @param {number} a
|
||||
//// * @param {T} b
|
||||
//// */
|
||||
////function /*1*/f<T>(a, b) {
|
||||
////}
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/**
|
||||
* @param {number} a
|
||||
* @param {T} b
|
||||
*/
|
||||
function f<T>(a: number, b: T) {
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,28 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
/////**
|
||||
//// * @param {number} x - the first parameter
|
||||
//// * @param {{ a: string, b: Date }} y - the most complex parameter
|
||||
//// * @param z - the best parameter
|
||||
//// * @param alpha - the other best parameter
|
||||
//// * @param {*} beta - I have no idea how this got here
|
||||
//// */
|
||||
////function f(/*1*/x, /*2*/y, /*3*/z: string, /*4*/alpha, /*5*/beta) {
|
||||
////}
|
||||
|
||||
verify.not.applicableRefactorAvailableAtMarker('3');
|
||||
verify.not.applicableRefactorAvailableAtMarker('4');
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/**
|
||||
* @param {number} x - the first parameter
|
||||
* @param {{ a: string, b: Date }} y - the most complex parameter
|
||||
* @param z - the best parameter
|
||||
* @param alpha - the other best parameter
|
||||
* @param {*} beta - I have no idea how this got here
|
||||
*/
|
||||
function f(x: number, y: {
|
||||
a: string;
|
||||
b: Date;
|
||||
}, z: string, alpha, beta: any) {
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @strict: true
|
||||
/////**
|
||||
//// * @param {*} x
|
||||
//// * @param {?} y
|
||||
//// * @param {number=} z
|
||||
//// * @param {...number} alpha
|
||||
//// * @param {function(this:{ a: string}, string, number): boolean} beta
|
||||
//// * @param {number?} gamma
|
||||
//// * @param {number!} delta
|
||||
//// */
|
||||
////function f(/*1*/x, /*2*/y, /*3*/z, /*4*/alpha, /*5*/beta, /*6*/gamma, /*7*/delta) {
|
||||
////}
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('5');
|
||||
verify.fileAfterApplyingRefactorAtMarker('5',
|
||||
`/**
|
||||
* @param {*} x
|
||||
* @param {?} y
|
||||
* @param {number=} z
|
||||
* @param {...number} alpha
|
||||
* @param {function(this:{ a: string}, string, number): boolean} beta
|
||||
* @param {number?} gamma
|
||||
* @param {number!} delta
|
||||
*/
|
||||
function f(x: any, y: any, z: number | undefined, alpha: number[], beta: (this: {
|
||||
a: string;
|
||||
}, arg1: string, arg2: number) => boolean, gamma: number | null, delta: number) {
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////class C {
|
||||
//// /** @type {number | null} */
|
||||
//// /*1*/p = null
|
||||
////}
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`class C {
|
||||
/** @type {number | null} */
|
||||
p: number | null = null;
|
||||
}`, 'Annotate with type from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,13 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////declare class C {
|
||||
//// /** @type {number | null} */
|
||||
//// /*1*/p;
|
||||
////}
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`declare class C {
|
||||
/** @type {number | null} */
|
||||
p: number | null;
|
||||
}`, 'Annotate with type from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
/////**
|
||||
//// * @param {number} x
|
||||
//// * @returns {number}
|
||||
//// */
|
||||
/////*1*/function f(x) {
|
||||
////}
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/**
|
||||
* @param {number} x
|
||||
* @returns {number}
|
||||
*/
|
||||
function f(x: number): number {
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,17 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
/////**
|
||||
//// * @param {number} x
|
||||
//// * @returns {number}
|
||||
//// */
|
||||
////var f = /*1*/function (x) {
|
||||
////}
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/**
|
||||
* @param {number} x
|
||||
* @returns {number}
|
||||
*/
|
||||
var f = function(x: number): number {
|
||||
}`, 'Annotate with types from JSDoc', 'annotate');
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
/////**
|
||||
//// * @param {?} x
|
||||
//// * @returns {number}
|
||||
//// */
|
||||
////var f = /*1*/x => x
|
||||
|
||||
verify.applicableRefactorAvailableAtMarker('1');
|
||||
verify.fileAfterApplyingRefactorAtMarker('1',
|
||||
`/**
|
||||
* @param {?} x
|
||||
* @returns {number}
|
||||
*/
|
||||
var f = (x: any): number => x`, 'Annotate with types from JSDoc', 'annotate');
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user