diff --git a/lib/tsc.js b/lib/tsc.js index dd19b4a1986..732778a081f 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -4787,6 +4787,7 @@ var ts; The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access: diag(2779, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access_2779", "The left-hand side of an assignment expression may not be an optional property access."), The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access: diag(2780, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access_2780", "The left-hand side of a 'for...in' statement may not be an optional property access."), The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access: diag(2781, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access_2781", "The left-hand side of a 'for...of' statement may not be an optional property access."), + _0_needs_an_explicit_type_annotation: diag(2782, ts.DiagnosticCategory.Message, "_0_needs_an_explicit_type_annotation_2782", "'{0}' needs an explicit type annotation."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -10941,6 +10942,10 @@ var ts; return !!node && !!(node.flags & 33554432); } ts.isInJsonFile = isInJsonFile; + function isSourceFileNotJson(file) { + return !isJsonSourceFile(file); + } + ts.isSourceFileNotJson = isSourceFileNotJson; function isInJSDoc(node) { return !!node && !!(node.flags & 4194304); } @@ -17787,6 +17792,9 @@ var ts; propertyAccess.name = parseRightSideOfDot(true, true); if (questionDotToken || expression.flags & 32) { propertyAccess.flags |= 32; + if (ts.isPrivateIdentifier(propertyAccess.name)) { + parseErrorAtRange(propertyAccess.name, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); + } } return finishNode(propertyAccess); } @@ -25607,7 +25615,7 @@ var ts; typeLiteralSymbol.members.set(symbol.escapedName, symbol); } function bindObjectLiteralExpression(node) { - if (inStrictMode) { + if (inStrictMode && !ts.isAssignmentTarget(node)) { var seen = ts.createUnderscoreEscapedMap(); for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; @@ -31074,6 +31082,9 @@ var ts; return ts.createIndexSignature(undefined, indexInfo.isReadonly ? [ts.createToken(138)] : undefined, [indexingParameter], typeNode); } function signatureToSignatureDeclarationHelper(signature, kind, context) { + var suppressAny = context.flags & 256; + if (suppressAny) + context.flags &= ~256; var typeParameters; var typeArguments; if (context.flags & 32 && signature.target && signature.mapper && signature.target.typeParameters) { @@ -31101,15 +31112,12 @@ var ts; } else { var returnType = getReturnTypeOfSignature(signature); - returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context); - } - if (context.flags & 256) { - if (returnTypeNode && returnTypeNode.kind === 125) { - returnTypeNode = undefined; + if (returnType && !(suppressAny && isTypeAny(returnType))) { + returnTypeNode = typeToTypeNodeHelper(returnType, context); + } + else if (!suppressAny) { + returnTypeNode = ts.createKeywordTypeNode(125); } - } - else if (!returnTypeNode) { - returnTypeNode = ts.createKeywordTypeNode(125); } context.approximateLength += 3; return ts.createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments); @@ -38948,7 +38956,8 @@ var ts; return false; } function isEmptyResolvedType(t) { - return t.properties.length === 0 && + return t !== anyFunctionType && + t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && !t.stringIndexInfo && @@ -42779,7 +42788,7 @@ var ts; return getTypeOfSymbol(symbol); } if (diagnostic && symbol.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(symbol))); + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_needs_an_explicit_type_annotation, symbolToString(symbol))); } } } @@ -43390,10 +43399,12 @@ var ts; return type; } function narrowTypeByOptionalChainContainment(type, operator, value, assumeTrue) { - var effectiveTrue = operator === 34 || operator === 36 ? assumeTrue : !assumeTrue; - var doubleEquals = operator === 34 || operator === 35; - var valueNonNullish = !(getTypeFacts(getTypeOfExpression(value)) & (doubleEquals ? 262144 : 65536)); - return effectiveTrue === valueNonNullish ? getTypeWithFacts(type, 2097152) : type; + var equalsOperator = operator === 34 || operator === 36; + var nullableFlags = operator === 34 || operator === 35 ? 98304 : 32768; + var valueType = getTypeOfExpression(value); + var removeNullable = equalsOperator !== assumeTrue && everyType(valueType, function (t) { return !!(t.flags & nullableFlags); }) || + equalsOperator === assumeTrue && everyType(valueType, function (t) { return !(t.flags & (3 | nullableFlags)); }); + return removeNullable ? getTypeWithFacts(type, 2097152) : type; } function narrowTypeByEquality(type, operator, value, assumeTrue) { if (type.flags & 1) { @@ -45950,10 +45961,6 @@ var ts; var assignmentKind = ts.getAssignmentTargetKind(node); var apparentType = getApparentType(assignmentKind !== 0 || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType); if (ts.isPrivateIdentifier(right)) { - if (ts.isOptionalChain(node)) { - grammarErrorOnNode(right, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); - return anyType; - } checkExternalEmitHelpers(node, 262144); } var isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType; @@ -52921,7 +52928,7 @@ var ts; } if (isInstancePropertyWithoutInitializer(member)) { var propName = member.name; - if (ts.isIdentifier(propName)) { + if (ts.isIdentifier(propName) || ts.isPrivateIdentifier(propName)) { var type = getTypeOfSymbol(getSymbolOfNode(member)); if (!(type.flags & 3 || getFalsyFlags(type) & 32768)) { if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) { @@ -55842,28 +55849,30 @@ var ts; default: throw ts.Debug.assertNever(prop, "Unexpected syntax kind:" + prop.kind); } - var effectiveName = ts.getPropertyNameForPropertyNameNode(name); - if (effectiveName === undefined) { - continue; - } - var existingKind = seen.get(effectiveName); - if (!existingKind) { - seen.set(effectiveName, currentKind); - } - else { - if ((currentKind & 12) && (existingKind & 12)) { - grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + if (!inDestructuring) { + var effectiveName = ts.getPropertyNameForPropertyNameNode(name); + if (effectiveName === undefined) { + continue; } - else if ((currentKind & 3) && (existingKind & 3)) { - if (existingKind !== 3 && currentKind !== existingKind) { - seen.set(effectiveName, currentKind | existingKind); - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } + var existingKind = seen.get(effectiveName); + if (!existingKind) { + seen.set(effectiveName, currentKind); } else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + if ((currentKind & 12) && (existingKind & 12)) { + grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + } + else if ((currentKind & 3) && (existingKind & 3)) { + if (existingKind !== 3 && currentKind !== existingKind) { + seen.set(effectiveName, currentKind | existingKind); + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } } } } @@ -73257,8 +73266,11 @@ var ts; var ts; (function (ts) { function getDeclarationDiagnostics(host, resolver, file) { + if (file && ts.isJsonSourceFile(file)) { + return []; + } var compilerOptions = host.getCompilerOptions(); - var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : host.getSourceFiles(), [transformDeclarations], false); + var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : ts.filter(host.getSourceFiles(), ts.isSourceFileNotJson), [transformDeclarations], false); return result.diagnostics; } ts.getDeclarationDiagnostics = getDeclarationDiagnostics; @@ -74803,11 +74815,12 @@ var ts; } else { var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); - var isJsonEmittedToSameLocation = ts.isJsonSourceFile(sourceFile) && + var isJsonFile = ts.isJsonSourceFile(sourceFile); + var isJsonEmittedToSameLocation = isJsonFile && ts.comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === 0; var jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath; var sourceMapFilePath = !jsFilePath || ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); - var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; + var declarationFilePath = (forceDtsPaths || (ts.getEmitDeclarations(options) && !isJsonFile)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, buildInfoPath: undefined }; } @@ -74842,7 +74855,7 @@ var ts; inputFileName; } function getOutputDeclarationFileName(inputFileName, configFile, ignoreCase) { - ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts")); + ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts") && !ts.fileExtensionIs(inputFileName, ".json")); return ts.changeExtension(getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir), ".d.ts"); } ts.getOutputDeclarationFileName = getOutputDeclarationFileName; @@ -75060,9 +75073,10 @@ var ts; return; } var sourceFiles = ts.isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles; - var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(sourceFiles, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : sourceFiles; + var filesForEmit = forceDtsEmit ? sourceFiles : ts.filter(sourceFiles, ts.isSourceFileNotJson); + var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(filesForEmit, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit; if (emitOnlyDtsFiles && !ts.getEmitDeclarations(compilerOptions)) { - sourceFiles.forEach(collectLinkedAliases); + filesForEmit.forEach(collectLinkedAliases); } var declarationTransform = ts.transformNodes(resolver, host, compilerOptions, inputListOrBundle, declarationTransformers, false); if (ts.length(declarationTransform.diagnostics)) { @@ -79877,7 +79891,7 @@ var ts; else if (ts.getEmitModuleKind(parsedRef.commandLine.options) === ts.ModuleKind.None) { for (var _c = 0, _d = parsedRef.commandLine.fileNames; _c < _d.length; _c++) { var fileName = _d[_c]; - if (!ts.fileExtensionIs(fileName, ".d.ts")) { + if (!ts.fileExtensionIs(fileName, ".d.ts") && !ts.fileExtensionIs(fileName, ".json")) { processSourceFile(ts.getOutputDeclarationFileName(fileName, parsedRef.commandLine, !host.useCaseSensitiveFileNames()), false, false, undefined); } } @@ -81101,7 +81115,7 @@ var ts; return referencedProject && getProjectReferenceOutputName(referencedProject, fileName); } function getProjectReferenceRedirectProject(fileName) { - if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts")) { + if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts") || ts.fileExtensionIs(fileName, ".json")) { return undefined; } return getResolvedProjectReferenceToRedirect(fileName); @@ -81148,7 +81162,7 @@ var ts; } else { ts.forEach(resolvedRef.commandLine.fileNames, function (fileName) { - if (!ts.fileExtensionIs(fileName, ".d.ts")) { + if (!ts.fileExtensionIs(fileName, ".d.ts") && !ts.fileExtensionIs(fileName, ".json")) { var outputDts = ts.getOutputDeclarationFileName(fileName, resolvedRef.commandLine, host.useCaseSensitiveFileNames()); mapFromToProjectReferenceRedirectSource.set(toPath(outputDts), fileName); } diff --git a/lib/tsserver.js b/lib/tsserver.js index a34dfb219a2..9a1f8fc1191 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -90,8 +90,8 @@ var __rest = (this && this.__rest) || function (s, e) { }; var ts; (function (ts) { - // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. - // If changing the text in this section, be sure to test `configureNightly` too. + // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values. + // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.8"; /** The version of the TypeScript compiler release */ ts.version = ts.versionMajorMinor + ".0-beta"; @@ -7192,6 +7192,7 @@ var ts; The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access: diag(2779, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access_2779", "The left-hand side of an assignment expression may not be an optional property access."), The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access: diag(2780, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access_2780", "The left-hand side of a 'for...in' statement may not be an optional property access."), The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access: diag(2781, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access_2781", "The left-hand side of a 'for...of' statement may not be an optional property access."), + _0_needs_an_explicit_type_annotation: diag(2782, ts.DiagnosticCategory.Message, "_0_needs_an_explicit_type_annotation_2782", "'{0}' needs an explicit type annotation."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -14093,6 +14094,10 @@ var ts; return !!node && !!(node.flags & 33554432 /* JsonFile */); } ts.isInJsonFile = isInJsonFile; + function isSourceFileNotJson(file) { + return !isJsonSourceFile(file); + } + ts.isSourceFileNotJson = isSourceFileNotJson; function isInJSDoc(node) { return !!node && !!(node.flags & 4194304 /* JSDoc */); } @@ -22255,10 +22260,12 @@ var ts; var propertyAccess = createNode(194 /* PropertyAccessExpression */, expression.pos); propertyAccess.expression = expression; propertyAccess.questionDotToken = questionDotToken; - // checker will error on private identifiers in optional chains, so don't have to catch them here propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true); if (questionDotToken || expression.flags & 32 /* OptionalChain */) { propertyAccess.flags |= 32 /* OptionalChain */; + if (ts.isPrivateIdentifier(propertyAccess.name)) { + parseErrorAtRange(propertyAccess.name, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); + } } return finishNode(propertyAccess); } @@ -31309,7 +31316,7 @@ var ts; ElementKind[ElementKind["Property"] = 1] = "Property"; ElementKind[ElementKind["Accessor"] = 2] = "Accessor"; })(ElementKind || (ElementKind = {})); - if (inStrictMode) { + if (inStrictMode && !ts.isAssignmentTarget(node)) { var seen = ts.createUnderscoreEscapedMap(); for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; @@ -37714,6 +37721,9 @@ var ts; /*decorators*/ undefined, indexInfo.isReadonly ? [ts.createToken(138 /* ReadonlyKeyword */)] : undefined, [indexingParameter], typeNode); } function signatureToSignatureDeclarationHelper(signature, kind, context) { + var suppressAny = context.flags & 256 /* SuppressAnyReturnType */; + if (suppressAny) + context.flags &= ~256 /* SuppressAnyReturnType */; // suppress only toplevel `any`s var typeParameters; var typeArguments; if (context.flags & 32 /* WriteTypeArgumentsOfSignature */ && signature.target && signature.mapper && signature.target.typeParameters) { @@ -37741,15 +37751,12 @@ var ts; } else { var returnType = getReturnTypeOfSignature(signature); - returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context); - } - if (context.flags & 256 /* SuppressAnyReturnType */) { - if (returnTypeNode && returnTypeNode.kind === 125 /* AnyKeyword */) { - returnTypeNode = undefined; + if (returnType && !(suppressAny && isTypeAny(returnType))) { + returnTypeNode = typeToTypeNodeHelper(returnType, context); + } + else if (!suppressAny) { + returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } - } - else if (!returnTypeNode) { - returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum return ts.createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments); @@ -46723,7 +46730,8 @@ var ts; return false; } function isEmptyResolvedType(t) { - return t.properties.length === 0 && + return t !== anyFunctionType && + t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && !t.stringIndexInfo && @@ -51127,7 +51135,7 @@ var ts; return getTypeOfSymbol(symbol); } if (diagnostic && symbol.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(symbol))); + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_needs_an_explicit_type_annotation, symbolToString(symbol))); } } } @@ -51828,13 +51836,22 @@ var ts; return type; } function narrowTypeByOptionalChainContainment(type, operator, value, assumeTrue) { - // We are in a branch of obj?.foo === value or obj?.foo !== value. We remove undefined and null from - // the type of obj if (a) the operator is === and the type of value doesn't include undefined or (b) the - // operator is !== and the type of value is undefined. - var effectiveTrue = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */ ? assumeTrue : !assumeTrue; - var doubleEquals = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */; - var valueNonNullish = !(getTypeFacts(getTypeOfExpression(value)) & (doubleEquals ? 262144 /* EQUndefinedOrNull */ : 65536 /* EQUndefined */)); - return effectiveTrue === valueNonNullish ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; + // We are in a branch of obj?.foo === value (or any one of the other equality operators). We narrow obj as follows: + // When operator is === and type of value excludes undefined, null and undefined is removed from type of obj in true branch. + // When operator is !== and type of value excludes undefined, null and undefined is removed from type of obj in false branch. + // When operator is == and type of value excludes null and undefined, null and undefined is removed from type of obj in true branch. + // When operator is != and type of value excludes null and undefined, null and undefined is removed from type of obj in false branch. + // When operator is === and type of value is undefined, null and undefined is removed from type of obj in false branch. + // When operator is !== and type of value is undefined, null and undefined is removed from type of obj in true branch. + // When operator is == and type of value is null or undefined, null and undefined is removed from type of obj in false branch. + // When operator is != and type of value is null or undefined, null and undefined is removed from type of obj in true branch. + var equalsOperator = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */; + var nullableFlags = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */ ? 98304 /* Nullable */ : 32768 /* Undefined */; + var valueType = getTypeOfExpression(value); + // Note that we include any and unknown in the exclusion test because their domain includes null and undefined. + var removeNullable = equalsOperator !== assumeTrue && everyType(valueType, function (t) { return !!(t.flags & nullableFlags); }) || + equalsOperator === assumeTrue && everyType(valueType, function (t) { return !(t.flags & (3 /* AnyOrUnknown */ | nullableFlags)); }); + return removeNullable ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; } function narrowTypeByEquality(type, operator, value, assumeTrue) { if (type.flags & 1 /* Any */) { @@ -54964,10 +54981,6 @@ var ts; var assignmentKind = ts.getAssignmentTargetKind(node); var apparentType = getApparentType(assignmentKind !== 0 /* None */ || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType); if (ts.isPrivateIdentifier(right)) { - if (ts.isOptionalChain(node)) { - grammarErrorOnNode(right, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); - return anyType; - } checkExternalEmitHelpers(node, 262144 /* ClassPrivateFieldGet */); } var isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType; @@ -63212,7 +63225,7 @@ var ts; } if (isInstancePropertyWithoutInitializer(member)) { var propName = member.name; - if (ts.isIdentifier(propName)) { + if (ts.isIdentifier(propName) || ts.isPrivateIdentifier(propName)) { var type = getTypeOfSymbol(getSymbolOfNode(member)); if (!(type.flags & 3 /* AnyOrUnknown */ || getFalsyFlags(type) & 32768 /* Undefined */)) { if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) { @@ -66449,28 +66462,30 @@ var ts; default: throw ts.Debug.assertNever(prop, "Unexpected syntax kind:" + prop.kind); } - var effectiveName = ts.getPropertyNameForPropertyNameNode(name); - if (effectiveName === undefined) { - continue; - } - var existingKind = seen.get(effectiveName); - if (!existingKind) { - seen.set(effectiveName, currentKind); - } - else { - if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { - grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + if (!inDestructuring) { + var effectiveName = ts.getPropertyNameForPropertyNameNode(name); + if (effectiveName === undefined) { + continue; } - else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { - if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { - seen.set(effectiveName, currentKind | existingKind); - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } + var existingKind = seen.get(effectiveName); + if (!existingKind) { + seen.set(effectiveName, currentKind); } else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { + grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + } + else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { + if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { + seen.set(effectiveName, currentKind | existingKind); + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } } } } @@ -89726,8 +89741,11 @@ var ts; var ts; (function (ts) { function getDeclarationDiagnostics(host, resolver, file) { + if (file && ts.isJsonSourceFile(file)) { + return []; // No declaration diagnostics for json for now + } var compilerOptions = host.getCompilerOptions(); - var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : host.getSourceFiles(), [transformDeclarations], /*allowDtsFiles*/ false); + var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : ts.filter(host.getSourceFiles(), ts.isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false); return result.diagnostics; } ts.getDeclarationDiagnostics = getDeclarationDiagnostics; @@ -91503,12 +91521,13 @@ var ts; } else { var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); + var isJsonFile = ts.isJsonSourceFile(sourceFile); // If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it - var isJsonEmittedToSameLocation = ts.isJsonSourceFile(sourceFile) && + var isJsonEmittedToSameLocation = isJsonFile && ts.comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === 0 /* EqualTo */; var jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath; var sourceMapFilePath = !jsFilePath || ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); - var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; + var declarationFilePath = (forceDtsPaths || (ts.getEmitDeclarations(options) && !isJsonFile)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, buildInfoPath: undefined }; } @@ -91549,7 +91568,7 @@ var ts; } /* @internal */ function getOutputDeclarationFileName(inputFileName, configFile, ignoreCase) { - ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */)); + ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(inputFileName, ".json" /* Json */)); return ts.changeExtension(getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir), ".d.ts" /* Dts */); } ts.getOutputDeclarationFileName = getOutputDeclarationFileName; @@ -91779,12 +91798,13 @@ var ts; return; } var sourceFiles = ts.isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles; + var filesForEmit = forceDtsEmit ? sourceFiles : ts.filter(sourceFiles, ts.isSourceFileNotJson); // Setup and perform the transformation to retrieve declarations from the input files - var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(sourceFiles, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : sourceFiles; + var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(filesForEmit, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit; if (emitOnlyDtsFiles && !ts.getEmitDeclarations(compilerOptions)) { // Checker wont collect the linked aliases since thats only done when declaration is enabled. // Do that here when emitting only dts files - sourceFiles.forEach(collectLinkedAliases); + filesForEmit.forEach(collectLinkedAliases); } var declarationTransform = ts.transformNodes(resolver, host, compilerOptions, inputListOrBundle, declarationTransformers, /*allowDtsFiles*/ false); if (ts.length(declarationTransform.diagnostics)) { @@ -97071,7 +97091,7 @@ var ts; else if (ts.getEmitModuleKind(parsedRef.commandLine.options) === ts.ModuleKind.None) { for (var _c = 0, _d = parsedRef.commandLine.fileNames; _c < _d.length; _c++) { var fileName = _d[_c]; - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { processSourceFile(ts.getOutputDeclarationFileName(fileName, parsedRef.commandLine, !host.useCaseSensitiveFileNames()), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined); } } @@ -98496,8 +98516,8 @@ var ts; return referencedProject && getProjectReferenceOutputName(referencedProject, fileName); } function getProjectReferenceRedirectProject(fileName) { - // Ignore dts - if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + // Ignore dts or any json files + if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) || ts.fileExtensionIs(fileName, ".json" /* Json */)) { return undefined; } // If this file is produced by a referenced project, we need to rewrite it to @@ -98551,7 +98571,7 @@ var ts; } else { ts.forEach(resolvedRef.commandLine.fileNames, function (fileName) { - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { var outputDts = ts.getOutputDeclarationFileName(fileName, resolvedRef.commandLine, host.useCaseSensitiveFileNames()); mapFromToProjectReferenceRedirectSource.set(toPath(outputDts), fileName); } @@ -110064,7 +110084,7 @@ var ts; switch (contextToken.kind) { case 27 /* CommaToken */: return containingNodeKind === 242 /* VariableDeclaration */ || - containingNodeKind === 243 /* VariableDeclarationList */ || + isVariableDeclarationListButNotTypeArgument(contextToken) || containingNodeKind === 225 /* VariableStatement */ || containingNodeKind === 248 /* EnumDeclaration */ || // enum a { foo, | isFunctionLikeButNotConstructor(containingNodeKind) || @@ -110175,6 +110195,10 @@ var ts; } return false; } + function isVariableDeclarationListButNotTypeArgument(node) { + return node.parent.kind === 243 /* VariableDeclarationList */ + && !ts.isPossiblyTypeArgumentPosition(node, sourceFile, typeChecker); + } /** * Filters out completion suggestions for named imports or exports. * @@ -138440,6 +138464,7 @@ var ts; scriptInfo.attachToProject(_this); }, function (removed) { return _this.detachScriptInfoFromProject(removed); }); var elapsed = ts.timestamp() - start; + this.projectService.sendUpdateGraphPerformanceEvent(elapsed); this.writeLog("Finishing updateGraphWorker: Project: " + this.getProjectName() + " Version: " + this.getProjectVersion() + " structureChanged: " + hasNewProgram + " Elapsed: " + elapsed + "ms"); if (this.hasAddedorRemovedFiles) { this.print(); @@ -139875,6 +139900,12 @@ var ts; this.eventHandler(event); }; /* @internal */ + ProjectService.prototype.sendUpdateGraphPerformanceEvent = function (durationMs) { + if (this.performanceEventHandler) { + this.performanceEventHandler({ kind: "UpdateGraph", durationMs: durationMs }); + } + }; + /* @internal */ ProjectService.prototype.delayUpdateProjectGraphAndEnsureProjectStructureForOpenFiles = function (project) { this.delayUpdateProjectGraph(project); this.delayEnsureProjectForOpenFiles(); @@ -141357,6 +141388,10 @@ var ts; } return info.sourceFileLike; }; + /*@internal*/ + ProjectService.prototype.setPerformanceEventHandler = function (performanceEventHandler) { + this.performanceEventHandler = performanceEventHandler; + }; ProjectService.prototype.setHostConfiguration = function (args) { var _this = this; if (args.file) { @@ -143107,11 +143142,20 @@ var ts; syntaxOnly: opts.syntaxOnly, }; this.projectService = new server.ProjectService(settings); + this.projectService.setPerformanceEventHandler(this.performanceEventHandler.bind(this)); this.gcTimer = new server.GcTimer(this.host, /*delay*/ 7000, this.logger); } Session.prototype.sendRequestCompletedEvent = function (requestId) { this.event({ request_seq: requestId }, "requestCompleted"); }; + Session.prototype.performanceEventHandler = function (event) { + switch (event.kind) { + case "UpdateGraph": { + this.updateGraphDurationMs = (this.updateGraphDurationMs || 0) + event.durationMs; + break; + } + } + }; Session.prototype.defaultEventHandler = function (event) { switch (event.eventName) { case server.ProjectsUpdatedInBackgroundEvent: @@ -143238,6 +143282,7 @@ var ts; command: cmdName, request_seq: reqSeq, success: success, + updateGraphDurationMs: this.updateGraphDurationMs, }; if (success) { var metadata = void 0; @@ -144498,6 +144543,7 @@ var ts; }; Session.prototype.onMessage = function (message) { this.gcTimer.scheduleCollect(); + this.updateGraphDurationMs = undefined; var start; if (this.logger.hasLevel(server.LogLevel.requestTime)) { start = this.hrtime(); diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 5ca50db8067..1855fae39b6 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -9154,6 +9154,7 @@ declare namespace ts.server { readonly syntaxOnly?: boolean; /** Tracks projects that we have already sent telemetry for. */ private readonly seenProjects; + private performanceEventHandler?; constructor(opts: ProjectServiceOptions); toPath(fileName: string): Path; private loadTypesMap; @@ -9383,6 +9384,7 @@ declare namespace ts.server { private readonly gcTimer; protected projectService: ProjectService; private changeSeq; + private updateGraphDurationMs; private currentRequestId; private errorCheck; protected host: ServerHost; @@ -9397,6 +9399,7 @@ declare namespace ts.server { private readonly noGetErrOnBackgroundUpdate?; constructor(opts: SessionOptions); private sendRequestCompletedEvent; + private performanceEventHandler; private defaultEventHandler; private projectsUpdatedInBackgroundEvent; logError(err: Error, cmd: string): void; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index c95ff9cd8e9..453cb80dbbf 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -240,8 +240,8 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. - // If changing the text in this section, be sure to test `configureNightly` too. + // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values. + // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.8"; /** The version of the TypeScript compiler release */ ts.version = ts.versionMajorMinor + ".0-beta"; @@ -7342,6 +7342,7 @@ var ts; The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access: diag(2779, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access_2779", "The left-hand side of an assignment expression may not be an optional property access."), The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access: diag(2780, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access_2780", "The left-hand side of a 'for...in' statement may not be an optional property access."), The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access: diag(2781, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access_2781", "The left-hand side of a 'for...of' statement may not be an optional property access."), + _0_needs_an_explicit_type_annotation: diag(2782, ts.DiagnosticCategory.Message, "_0_needs_an_explicit_type_annotation_2782", "'{0}' needs an explicit type annotation."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -14243,6 +14244,10 @@ var ts; return !!node && !!(node.flags & 33554432 /* JsonFile */); } ts.isInJsonFile = isInJsonFile; + function isSourceFileNotJson(file) { + return !isJsonSourceFile(file); + } + ts.isSourceFileNotJson = isSourceFileNotJson; function isInJSDoc(node) { return !!node && !!(node.flags & 4194304 /* JSDoc */); } @@ -22405,10 +22410,12 @@ var ts; var propertyAccess = createNode(194 /* PropertyAccessExpression */, expression.pos); propertyAccess.expression = expression; propertyAccess.questionDotToken = questionDotToken; - // checker will error on private identifiers in optional chains, so don't have to catch them here propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true); if (questionDotToken || expression.flags & 32 /* OptionalChain */) { propertyAccess.flags |= 32 /* OptionalChain */; + if (ts.isPrivateIdentifier(propertyAccess.name)) { + parseErrorAtRange(propertyAccess.name, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); + } } return finishNode(propertyAccess); } @@ -31459,7 +31466,7 @@ var ts; ElementKind[ElementKind["Property"] = 1] = "Property"; ElementKind[ElementKind["Accessor"] = 2] = "Accessor"; })(ElementKind || (ElementKind = {})); - if (inStrictMode) { + if (inStrictMode && !ts.isAssignmentTarget(node)) { var seen = ts.createUnderscoreEscapedMap(); for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; @@ -37864,6 +37871,9 @@ var ts; /*decorators*/ undefined, indexInfo.isReadonly ? [ts.createToken(138 /* ReadonlyKeyword */)] : undefined, [indexingParameter], typeNode); } function signatureToSignatureDeclarationHelper(signature, kind, context) { + var suppressAny = context.flags & 256 /* SuppressAnyReturnType */; + if (suppressAny) + context.flags &= ~256 /* SuppressAnyReturnType */; // suppress only toplevel `any`s var typeParameters; var typeArguments; if (context.flags & 32 /* WriteTypeArgumentsOfSignature */ && signature.target && signature.mapper && signature.target.typeParameters) { @@ -37891,15 +37901,12 @@ var ts; } else { var returnType = getReturnTypeOfSignature(signature); - returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context); - } - if (context.flags & 256 /* SuppressAnyReturnType */) { - if (returnTypeNode && returnTypeNode.kind === 125 /* AnyKeyword */) { - returnTypeNode = undefined; + if (returnType && !(suppressAny && isTypeAny(returnType))) { + returnTypeNode = typeToTypeNodeHelper(returnType, context); + } + else if (!suppressAny) { + returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } - } - else if (!returnTypeNode) { - returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum return ts.createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments); @@ -46873,7 +46880,8 @@ var ts; return false; } function isEmptyResolvedType(t) { - return t.properties.length === 0 && + return t !== anyFunctionType && + t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && !t.stringIndexInfo && @@ -51277,7 +51285,7 @@ var ts; return getTypeOfSymbol(symbol); } if (diagnostic && symbol.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(symbol))); + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_needs_an_explicit_type_annotation, symbolToString(symbol))); } } } @@ -51978,13 +51986,22 @@ var ts; return type; } function narrowTypeByOptionalChainContainment(type, operator, value, assumeTrue) { - // We are in a branch of obj?.foo === value or obj?.foo !== value. We remove undefined and null from - // the type of obj if (a) the operator is === and the type of value doesn't include undefined or (b) the - // operator is !== and the type of value is undefined. - var effectiveTrue = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */ ? assumeTrue : !assumeTrue; - var doubleEquals = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */; - var valueNonNullish = !(getTypeFacts(getTypeOfExpression(value)) & (doubleEquals ? 262144 /* EQUndefinedOrNull */ : 65536 /* EQUndefined */)); - return effectiveTrue === valueNonNullish ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; + // We are in a branch of obj?.foo === value (or any one of the other equality operators). We narrow obj as follows: + // When operator is === and type of value excludes undefined, null and undefined is removed from type of obj in true branch. + // When operator is !== and type of value excludes undefined, null and undefined is removed from type of obj in false branch. + // When operator is == and type of value excludes null and undefined, null and undefined is removed from type of obj in true branch. + // When operator is != and type of value excludes null and undefined, null and undefined is removed from type of obj in false branch. + // When operator is === and type of value is undefined, null and undefined is removed from type of obj in false branch. + // When operator is !== and type of value is undefined, null and undefined is removed from type of obj in true branch. + // When operator is == and type of value is null or undefined, null and undefined is removed from type of obj in false branch. + // When operator is != and type of value is null or undefined, null and undefined is removed from type of obj in true branch. + var equalsOperator = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */; + var nullableFlags = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */ ? 98304 /* Nullable */ : 32768 /* Undefined */; + var valueType = getTypeOfExpression(value); + // Note that we include any and unknown in the exclusion test because their domain includes null and undefined. + var removeNullable = equalsOperator !== assumeTrue && everyType(valueType, function (t) { return !!(t.flags & nullableFlags); }) || + equalsOperator === assumeTrue && everyType(valueType, function (t) { return !(t.flags & (3 /* AnyOrUnknown */ | nullableFlags)); }); + return removeNullable ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; } function narrowTypeByEquality(type, operator, value, assumeTrue) { if (type.flags & 1 /* Any */) { @@ -55114,10 +55131,6 @@ var ts; var assignmentKind = ts.getAssignmentTargetKind(node); var apparentType = getApparentType(assignmentKind !== 0 /* None */ || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType); if (ts.isPrivateIdentifier(right)) { - if (ts.isOptionalChain(node)) { - grammarErrorOnNode(right, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); - return anyType; - } checkExternalEmitHelpers(node, 262144 /* ClassPrivateFieldGet */); } var isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType; @@ -63362,7 +63375,7 @@ var ts; } if (isInstancePropertyWithoutInitializer(member)) { var propName = member.name; - if (ts.isIdentifier(propName)) { + if (ts.isIdentifier(propName) || ts.isPrivateIdentifier(propName)) { var type = getTypeOfSymbol(getSymbolOfNode(member)); if (!(type.flags & 3 /* AnyOrUnknown */ || getFalsyFlags(type) & 32768 /* Undefined */)) { if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) { @@ -66599,28 +66612,30 @@ var ts; default: throw ts.Debug.assertNever(prop, "Unexpected syntax kind:" + prop.kind); } - var effectiveName = ts.getPropertyNameForPropertyNameNode(name); - if (effectiveName === undefined) { - continue; - } - var existingKind = seen.get(effectiveName); - if (!existingKind) { - seen.set(effectiveName, currentKind); - } - else { - if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { - grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + if (!inDestructuring) { + var effectiveName = ts.getPropertyNameForPropertyNameNode(name); + if (effectiveName === undefined) { + continue; } - else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { - if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { - seen.set(effectiveName, currentKind | existingKind); - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } + var existingKind = seen.get(effectiveName); + if (!existingKind) { + seen.set(effectiveName, currentKind); } else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { + grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + } + else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { + if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { + seen.set(effectiveName, currentKind | existingKind); + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } } } } @@ -89876,8 +89891,11 @@ var ts; var ts; (function (ts) { function getDeclarationDiagnostics(host, resolver, file) { + if (file && ts.isJsonSourceFile(file)) { + return []; // No declaration diagnostics for json for now + } var compilerOptions = host.getCompilerOptions(); - var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : host.getSourceFiles(), [transformDeclarations], /*allowDtsFiles*/ false); + var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : ts.filter(host.getSourceFiles(), ts.isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false); return result.diagnostics; } ts.getDeclarationDiagnostics = getDeclarationDiagnostics; @@ -91653,12 +91671,13 @@ var ts; } else { var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); + var isJsonFile = ts.isJsonSourceFile(sourceFile); // If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it - var isJsonEmittedToSameLocation = ts.isJsonSourceFile(sourceFile) && + var isJsonEmittedToSameLocation = isJsonFile && ts.comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === 0 /* EqualTo */; var jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath; var sourceMapFilePath = !jsFilePath || ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); - var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; + var declarationFilePath = (forceDtsPaths || (ts.getEmitDeclarations(options) && !isJsonFile)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, buildInfoPath: undefined }; } @@ -91699,7 +91718,7 @@ var ts; } /* @internal */ function getOutputDeclarationFileName(inputFileName, configFile, ignoreCase) { - ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */)); + ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(inputFileName, ".json" /* Json */)); return ts.changeExtension(getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir), ".d.ts" /* Dts */); } ts.getOutputDeclarationFileName = getOutputDeclarationFileName; @@ -91929,12 +91948,13 @@ var ts; return; } var sourceFiles = ts.isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles; + var filesForEmit = forceDtsEmit ? sourceFiles : ts.filter(sourceFiles, ts.isSourceFileNotJson); // Setup and perform the transformation to retrieve declarations from the input files - var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(sourceFiles, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : sourceFiles; + var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(filesForEmit, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit; if (emitOnlyDtsFiles && !ts.getEmitDeclarations(compilerOptions)) { // Checker wont collect the linked aliases since thats only done when declaration is enabled. // Do that here when emitting only dts files - sourceFiles.forEach(collectLinkedAliases); + filesForEmit.forEach(collectLinkedAliases); } var declarationTransform = ts.transformNodes(resolver, host, compilerOptions, inputListOrBundle, declarationTransformers, /*allowDtsFiles*/ false); if (ts.length(declarationTransform.diagnostics)) { @@ -97221,7 +97241,7 @@ var ts; else if (ts.getEmitModuleKind(parsedRef.commandLine.options) === ts.ModuleKind.None) { for (var _c = 0, _d = parsedRef.commandLine.fileNames; _c < _d.length; _c++) { var fileName = _d[_c]; - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { processSourceFile(ts.getOutputDeclarationFileName(fileName, parsedRef.commandLine, !host.useCaseSensitiveFileNames()), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined); } } @@ -98646,8 +98666,8 @@ var ts; return referencedProject && getProjectReferenceOutputName(referencedProject, fileName); } function getProjectReferenceRedirectProject(fileName) { - // Ignore dts - if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + // Ignore dts or any json files + if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) || ts.fileExtensionIs(fileName, ".json" /* Json */)) { return undefined; } // If this file is produced by a referenced project, we need to rewrite it to @@ -98701,7 +98721,7 @@ var ts; } else { ts.forEach(resolvedRef.commandLine.fileNames, function (fileName) { - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { var outputDts = ts.getOutputDeclarationFileName(fileName, resolvedRef.commandLine, host.useCaseSensitiveFileNames()); mapFromToProjectReferenceRedirectSource.set(toPath(outputDts), fileName); } @@ -110587,7 +110607,7 @@ var ts; switch (contextToken.kind) { case 27 /* CommaToken */: return containingNodeKind === 242 /* VariableDeclaration */ || - containingNodeKind === 243 /* VariableDeclarationList */ || + isVariableDeclarationListButNotTypeArgument(contextToken) || containingNodeKind === 225 /* VariableStatement */ || containingNodeKind === 248 /* EnumDeclaration */ || // enum a { foo, | isFunctionLikeButNotConstructor(containingNodeKind) || @@ -110698,6 +110718,10 @@ var ts; } return false; } + function isVariableDeclarationListButNotTypeArgument(node) { + return node.parent.kind === 243 /* VariableDeclarationList */ + && !ts.isPossiblyTypeArgumentPosition(node, sourceFile, typeChecker); + } /** * Filters out completion suggestions for named imports or exports. * @@ -138590,6 +138614,7 @@ var ts; scriptInfo.attachToProject(_this); }, function (removed) { return _this.detachScriptInfoFromProject(removed); }); var elapsed = ts.timestamp() - start; + this.projectService.sendUpdateGraphPerformanceEvent(elapsed); this.writeLog("Finishing updateGraphWorker: Project: " + this.getProjectName() + " Version: " + this.getProjectVersion() + " structureChanged: " + hasNewProgram + " Elapsed: " + elapsed + "ms"); if (this.hasAddedorRemovedFiles) { this.print(); @@ -140025,6 +140050,12 @@ var ts; this.eventHandler(event); }; /* @internal */ + ProjectService.prototype.sendUpdateGraphPerformanceEvent = function (durationMs) { + if (this.performanceEventHandler) { + this.performanceEventHandler({ kind: "UpdateGraph", durationMs: durationMs }); + } + }; + /* @internal */ ProjectService.prototype.delayUpdateProjectGraphAndEnsureProjectStructureForOpenFiles = function (project) { this.delayUpdateProjectGraph(project); this.delayEnsureProjectForOpenFiles(); @@ -141507,6 +141538,10 @@ var ts; } return info.sourceFileLike; }; + /*@internal*/ + ProjectService.prototype.setPerformanceEventHandler = function (performanceEventHandler) { + this.performanceEventHandler = performanceEventHandler; + }; ProjectService.prototype.setHostConfiguration = function (args) { var _this = this; if (args.file) { @@ -143257,11 +143292,20 @@ var ts; syntaxOnly: opts.syntaxOnly, }; this.projectService = new server.ProjectService(settings); + this.projectService.setPerformanceEventHandler(this.performanceEventHandler.bind(this)); this.gcTimer = new server.GcTimer(this.host, /*delay*/ 7000, this.logger); } Session.prototype.sendRequestCompletedEvent = function (requestId) { this.event({ request_seq: requestId }, "requestCompleted"); }; + Session.prototype.performanceEventHandler = function (event) { + switch (event.kind) { + case "UpdateGraph": { + this.updateGraphDurationMs = (this.updateGraphDurationMs || 0) + event.durationMs; + break; + } + } + }; Session.prototype.defaultEventHandler = function (event) { switch (event.eventName) { case server.ProjectsUpdatedInBackgroundEvent: @@ -143388,6 +143432,7 @@ var ts; command: cmdName, request_seq: reqSeq, success: success, + updateGraphDurationMs: this.updateGraphDurationMs, }; if (success) { var metadata = void 0; @@ -144648,6 +144693,7 @@ var ts; }; Session.prototype.onMessage = function (message) { this.gcTimer.scheduleCollect(); + this.updateGraphDurationMs = undefined; var start; if (this.logger.hasLevel(server.LogLevel.requestTime)) { start = this.hrtime(); diff --git a/lib/typescript.js b/lib/typescript.js index cc5ccbfe84b..c58724a0d0d 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -229,8 +229,8 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. - // If changing the text in this section, be sure to test `configureNightly` too. + // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values. + // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.8"; /** The version of the TypeScript compiler release */ ts.version = ts.versionMajorMinor + ".0-beta"; @@ -7331,6 +7331,7 @@ var ts; The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access: diag(2779, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access_2779", "The left-hand side of an assignment expression may not be an optional property access."), The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access: diag(2780, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access_2780", "The left-hand side of a 'for...in' statement may not be an optional property access."), The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access: diag(2781, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access_2781", "The left-hand side of a 'for...of' statement may not be an optional property access."), + _0_needs_an_explicit_type_annotation: diag(2782, ts.DiagnosticCategory.Message, "_0_needs_an_explicit_type_annotation_2782", "'{0}' needs an explicit type annotation."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -14232,6 +14233,10 @@ var ts; return !!node && !!(node.flags & 33554432 /* JsonFile */); } ts.isInJsonFile = isInJsonFile; + function isSourceFileNotJson(file) { + return !isJsonSourceFile(file); + } + ts.isSourceFileNotJson = isSourceFileNotJson; function isInJSDoc(node) { return !!node && !!(node.flags & 4194304 /* JSDoc */); } @@ -22394,10 +22399,12 @@ var ts; var propertyAccess = createNode(194 /* PropertyAccessExpression */, expression.pos); propertyAccess.expression = expression; propertyAccess.questionDotToken = questionDotToken; - // checker will error on private identifiers in optional chains, so don't have to catch them here propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true); if (questionDotToken || expression.flags & 32 /* OptionalChain */) { propertyAccess.flags |= 32 /* OptionalChain */; + if (ts.isPrivateIdentifier(propertyAccess.name)) { + parseErrorAtRange(propertyAccess.name, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); + } } return finishNode(propertyAccess); } @@ -31448,7 +31455,7 @@ var ts; ElementKind[ElementKind["Property"] = 1] = "Property"; ElementKind[ElementKind["Accessor"] = 2] = "Accessor"; })(ElementKind || (ElementKind = {})); - if (inStrictMode) { + if (inStrictMode && !ts.isAssignmentTarget(node)) { var seen = ts.createUnderscoreEscapedMap(); for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; @@ -37853,6 +37860,9 @@ var ts; /*decorators*/ undefined, indexInfo.isReadonly ? [ts.createToken(138 /* ReadonlyKeyword */)] : undefined, [indexingParameter], typeNode); } function signatureToSignatureDeclarationHelper(signature, kind, context) { + var suppressAny = context.flags & 256 /* SuppressAnyReturnType */; + if (suppressAny) + context.flags &= ~256 /* SuppressAnyReturnType */; // suppress only toplevel `any`s var typeParameters; var typeArguments; if (context.flags & 32 /* WriteTypeArgumentsOfSignature */ && signature.target && signature.mapper && signature.target.typeParameters) { @@ -37880,15 +37890,12 @@ var ts; } else { var returnType = getReturnTypeOfSignature(signature); - returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context); - } - if (context.flags & 256 /* SuppressAnyReturnType */) { - if (returnTypeNode && returnTypeNode.kind === 125 /* AnyKeyword */) { - returnTypeNode = undefined; + if (returnType && !(suppressAny && isTypeAny(returnType))) { + returnTypeNode = typeToTypeNodeHelper(returnType, context); + } + else if (!suppressAny) { + returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } - } - else if (!returnTypeNode) { - returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum return ts.createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments); @@ -46862,7 +46869,8 @@ var ts; return false; } function isEmptyResolvedType(t) { - return t.properties.length === 0 && + return t !== anyFunctionType && + t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && !t.stringIndexInfo && @@ -51266,7 +51274,7 @@ var ts; return getTypeOfSymbol(symbol); } if (diagnostic && symbol.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(symbol))); + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_needs_an_explicit_type_annotation, symbolToString(symbol))); } } } @@ -51967,13 +51975,22 @@ var ts; return type; } function narrowTypeByOptionalChainContainment(type, operator, value, assumeTrue) { - // We are in a branch of obj?.foo === value or obj?.foo !== value. We remove undefined and null from - // the type of obj if (a) the operator is === and the type of value doesn't include undefined or (b) the - // operator is !== and the type of value is undefined. - var effectiveTrue = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */ ? assumeTrue : !assumeTrue; - var doubleEquals = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */; - var valueNonNullish = !(getTypeFacts(getTypeOfExpression(value)) & (doubleEquals ? 262144 /* EQUndefinedOrNull */ : 65536 /* EQUndefined */)); - return effectiveTrue === valueNonNullish ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; + // We are in a branch of obj?.foo === value (or any one of the other equality operators). We narrow obj as follows: + // When operator is === and type of value excludes undefined, null and undefined is removed from type of obj in true branch. + // When operator is !== and type of value excludes undefined, null and undefined is removed from type of obj in false branch. + // When operator is == and type of value excludes null and undefined, null and undefined is removed from type of obj in true branch. + // When operator is != and type of value excludes null and undefined, null and undefined is removed from type of obj in false branch. + // When operator is === and type of value is undefined, null and undefined is removed from type of obj in false branch. + // When operator is !== and type of value is undefined, null and undefined is removed from type of obj in true branch. + // When operator is == and type of value is null or undefined, null and undefined is removed from type of obj in false branch. + // When operator is != and type of value is null or undefined, null and undefined is removed from type of obj in true branch. + var equalsOperator = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */; + var nullableFlags = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */ ? 98304 /* Nullable */ : 32768 /* Undefined */; + var valueType = getTypeOfExpression(value); + // Note that we include any and unknown in the exclusion test because their domain includes null and undefined. + var removeNullable = equalsOperator !== assumeTrue && everyType(valueType, function (t) { return !!(t.flags & nullableFlags); }) || + equalsOperator === assumeTrue && everyType(valueType, function (t) { return !(t.flags & (3 /* AnyOrUnknown */ | nullableFlags)); }); + return removeNullable ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; } function narrowTypeByEquality(type, operator, value, assumeTrue) { if (type.flags & 1 /* Any */) { @@ -55103,10 +55120,6 @@ var ts; var assignmentKind = ts.getAssignmentTargetKind(node); var apparentType = getApparentType(assignmentKind !== 0 /* None */ || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType); if (ts.isPrivateIdentifier(right)) { - if (ts.isOptionalChain(node)) { - grammarErrorOnNode(right, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); - return anyType; - } checkExternalEmitHelpers(node, 262144 /* ClassPrivateFieldGet */); } var isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType; @@ -63351,7 +63364,7 @@ var ts; } if (isInstancePropertyWithoutInitializer(member)) { var propName = member.name; - if (ts.isIdentifier(propName)) { + if (ts.isIdentifier(propName) || ts.isPrivateIdentifier(propName)) { var type = getTypeOfSymbol(getSymbolOfNode(member)); if (!(type.flags & 3 /* AnyOrUnknown */ || getFalsyFlags(type) & 32768 /* Undefined */)) { if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) { @@ -66588,28 +66601,30 @@ var ts; default: throw ts.Debug.assertNever(prop, "Unexpected syntax kind:" + prop.kind); } - var effectiveName = ts.getPropertyNameForPropertyNameNode(name); - if (effectiveName === undefined) { - continue; - } - var existingKind = seen.get(effectiveName); - if (!existingKind) { - seen.set(effectiveName, currentKind); - } - else { - if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { - grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + if (!inDestructuring) { + var effectiveName = ts.getPropertyNameForPropertyNameNode(name); + if (effectiveName === undefined) { + continue; } - else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { - if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { - seen.set(effectiveName, currentKind | existingKind); - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } + var existingKind = seen.get(effectiveName); + if (!existingKind) { + seen.set(effectiveName, currentKind); } else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { + grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + } + else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { + if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { + seen.set(effectiveName, currentKind | existingKind); + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } } } } @@ -89865,8 +89880,11 @@ var ts; var ts; (function (ts) { function getDeclarationDiagnostics(host, resolver, file) { + if (file && ts.isJsonSourceFile(file)) { + return []; // No declaration diagnostics for json for now + } var compilerOptions = host.getCompilerOptions(); - var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : host.getSourceFiles(), [transformDeclarations], /*allowDtsFiles*/ false); + var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : ts.filter(host.getSourceFiles(), ts.isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false); return result.diagnostics; } ts.getDeclarationDiagnostics = getDeclarationDiagnostics; @@ -91642,12 +91660,13 @@ var ts; } else { var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); + var isJsonFile = ts.isJsonSourceFile(sourceFile); // If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it - var isJsonEmittedToSameLocation = ts.isJsonSourceFile(sourceFile) && + var isJsonEmittedToSameLocation = isJsonFile && ts.comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === 0 /* EqualTo */; var jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath; var sourceMapFilePath = !jsFilePath || ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); - var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; + var declarationFilePath = (forceDtsPaths || (ts.getEmitDeclarations(options) && !isJsonFile)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, buildInfoPath: undefined }; } @@ -91688,7 +91707,7 @@ var ts; } /* @internal */ function getOutputDeclarationFileName(inputFileName, configFile, ignoreCase) { - ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */)); + ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(inputFileName, ".json" /* Json */)); return ts.changeExtension(getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir), ".d.ts" /* Dts */); } ts.getOutputDeclarationFileName = getOutputDeclarationFileName; @@ -91918,12 +91937,13 @@ var ts; return; } var sourceFiles = ts.isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles; + var filesForEmit = forceDtsEmit ? sourceFiles : ts.filter(sourceFiles, ts.isSourceFileNotJson); // Setup and perform the transformation to retrieve declarations from the input files - var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(sourceFiles, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : sourceFiles; + var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(filesForEmit, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit; if (emitOnlyDtsFiles && !ts.getEmitDeclarations(compilerOptions)) { // Checker wont collect the linked aliases since thats only done when declaration is enabled. // Do that here when emitting only dts files - sourceFiles.forEach(collectLinkedAliases); + filesForEmit.forEach(collectLinkedAliases); } var declarationTransform = ts.transformNodes(resolver, host, compilerOptions, inputListOrBundle, declarationTransformers, /*allowDtsFiles*/ false); if (ts.length(declarationTransform.diagnostics)) { @@ -97210,7 +97230,7 @@ var ts; else if (ts.getEmitModuleKind(parsedRef.commandLine.options) === ts.ModuleKind.None) { for (var _c = 0, _d = parsedRef.commandLine.fileNames; _c < _d.length; _c++) { var fileName = _d[_c]; - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { processSourceFile(ts.getOutputDeclarationFileName(fileName, parsedRef.commandLine, !host.useCaseSensitiveFileNames()), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined); } } @@ -98635,8 +98655,8 @@ var ts; return referencedProject && getProjectReferenceOutputName(referencedProject, fileName); } function getProjectReferenceRedirectProject(fileName) { - // Ignore dts - if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + // Ignore dts or any json files + if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) || ts.fileExtensionIs(fileName, ".json" /* Json */)) { return undefined; } // If this file is produced by a referenced project, we need to rewrite it to @@ -98690,7 +98710,7 @@ var ts; } else { ts.forEach(resolvedRef.commandLine.fileNames, function (fileName) { - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { var outputDts = ts.getOutputDeclarationFileName(fileName, resolvedRef.commandLine, host.useCaseSensitiveFileNames()); mapFromToProjectReferenceRedirectSource.set(toPath(outputDts), fileName); } @@ -110576,7 +110596,7 @@ var ts; switch (contextToken.kind) { case 27 /* CommaToken */: return containingNodeKind === 242 /* VariableDeclaration */ || - containingNodeKind === 243 /* VariableDeclarationList */ || + isVariableDeclarationListButNotTypeArgument(contextToken) || containingNodeKind === 225 /* VariableStatement */ || containingNodeKind === 248 /* EnumDeclaration */ || // enum a { foo, | isFunctionLikeButNotConstructor(containingNodeKind) || @@ -110687,6 +110707,10 @@ var ts; } return false; } + function isVariableDeclarationListButNotTypeArgument(node) { + return node.parent.kind === 243 /* VariableDeclarationList */ + && !ts.isPossiblyTypeArgumentPosition(node, sourceFile, typeChecker); + } /** * Filters out completion suggestions for named imports or exports. * diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index c63e7e84786..b01b3510b39 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -229,8 +229,8 @@ var ts; })(ts || (ts = {})); var ts; (function (ts) { - // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. - // If changing the text in this section, be sure to test `configureNightly` too. + // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values. + // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.8"; /** The version of the TypeScript compiler release */ ts.version = ts.versionMajorMinor + ".0-beta"; @@ -7331,6 +7331,7 @@ var ts; The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access: diag(2779, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access_2779", "The left-hand side of an assignment expression may not be an optional property access."), The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access: diag(2780, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access_2780", "The left-hand side of a 'for...in' statement may not be an optional property access."), The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access: diag(2781, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access_2781", "The left-hand side of a 'for...of' statement may not be an optional property access."), + _0_needs_an_explicit_type_annotation: diag(2782, ts.DiagnosticCategory.Message, "_0_needs_an_explicit_type_annotation_2782", "'{0}' needs an explicit type annotation."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -14232,6 +14233,10 @@ var ts; return !!node && !!(node.flags & 33554432 /* JsonFile */); } ts.isInJsonFile = isInJsonFile; + function isSourceFileNotJson(file) { + return !isJsonSourceFile(file); + } + ts.isSourceFileNotJson = isSourceFileNotJson; function isInJSDoc(node) { return !!node && !!(node.flags & 4194304 /* JSDoc */); } @@ -22394,10 +22399,12 @@ var ts; var propertyAccess = createNode(194 /* PropertyAccessExpression */, expression.pos); propertyAccess.expression = expression; propertyAccess.questionDotToken = questionDotToken; - // checker will error on private identifiers in optional chains, so don't have to catch them here propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true); if (questionDotToken || expression.flags & 32 /* OptionalChain */) { propertyAccess.flags |= 32 /* OptionalChain */; + if (ts.isPrivateIdentifier(propertyAccess.name)) { + parseErrorAtRange(propertyAccess.name, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); + } } return finishNode(propertyAccess); } @@ -31448,7 +31455,7 @@ var ts; ElementKind[ElementKind["Property"] = 1] = "Property"; ElementKind[ElementKind["Accessor"] = 2] = "Accessor"; })(ElementKind || (ElementKind = {})); - if (inStrictMode) { + if (inStrictMode && !ts.isAssignmentTarget(node)) { var seen = ts.createUnderscoreEscapedMap(); for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; @@ -37853,6 +37860,9 @@ var ts; /*decorators*/ undefined, indexInfo.isReadonly ? [ts.createToken(138 /* ReadonlyKeyword */)] : undefined, [indexingParameter], typeNode); } function signatureToSignatureDeclarationHelper(signature, kind, context) { + var suppressAny = context.flags & 256 /* SuppressAnyReturnType */; + if (suppressAny) + context.flags &= ~256 /* SuppressAnyReturnType */; // suppress only toplevel `any`s var typeParameters; var typeArguments; if (context.flags & 32 /* WriteTypeArgumentsOfSignature */ && signature.target && signature.mapper && signature.target.typeParameters) { @@ -37880,15 +37890,12 @@ var ts; } else { var returnType = getReturnTypeOfSignature(signature); - returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context); - } - if (context.flags & 256 /* SuppressAnyReturnType */) { - if (returnTypeNode && returnTypeNode.kind === 125 /* AnyKeyword */) { - returnTypeNode = undefined; + if (returnType && !(suppressAny && isTypeAny(returnType))) { + returnTypeNode = typeToTypeNodeHelper(returnType, context); + } + else if (!suppressAny) { + returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } - } - else if (!returnTypeNode) { - returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum return ts.createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments); @@ -46862,7 +46869,8 @@ var ts; return false; } function isEmptyResolvedType(t) { - return t.properties.length === 0 && + return t !== anyFunctionType && + t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && !t.stringIndexInfo && @@ -51266,7 +51274,7 @@ var ts; return getTypeOfSymbol(symbol); } if (diagnostic && symbol.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(symbol))); + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_needs_an_explicit_type_annotation, symbolToString(symbol))); } } } @@ -51967,13 +51975,22 @@ var ts; return type; } function narrowTypeByOptionalChainContainment(type, operator, value, assumeTrue) { - // We are in a branch of obj?.foo === value or obj?.foo !== value. We remove undefined and null from - // the type of obj if (a) the operator is === and the type of value doesn't include undefined or (b) the - // operator is !== and the type of value is undefined. - var effectiveTrue = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */ ? assumeTrue : !assumeTrue; - var doubleEquals = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */; - var valueNonNullish = !(getTypeFacts(getTypeOfExpression(value)) & (doubleEquals ? 262144 /* EQUndefinedOrNull */ : 65536 /* EQUndefined */)); - return effectiveTrue === valueNonNullish ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; + // We are in a branch of obj?.foo === value (or any one of the other equality operators). We narrow obj as follows: + // When operator is === and type of value excludes undefined, null and undefined is removed from type of obj in true branch. + // When operator is !== and type of value excludes undefined, null and undefined is removed from type of obj in false branch. + // When operator is == and type of value excludes null and undefined, null and undefined is removed from type of obj in true branch. + // When operator is != and type of value excludes null and undefined, null and undefined is removed from type of obj in false branch. + // When operator is === and type of value is undefined, null and undefined is removed from type of obj in false branch. + // When operator is !== and type of value is undefined, null and undefined is removed from type of obj in true branch. + // When operator is == and type of value is null or undefined, null and undefined is removed from type of obj in false branch. + // When operator is != and type of value is null or undefined, null and undefined is removed from type of obj in true branch. + var equalsOperator = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */; + var nullableFlags = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */ ? 98304 /* Nullable */ : 32768 /* Undefined */; + var valueType = getTypeOfExpression(value); + // Note that we include any and unknown in the exclusion test because their domain includes null and undefined. + var removeNullable = equalsOperator !== assumeTrue && everyType(valueType, function (t) { return !!(t.flags & nullableFlags); }) || + equalsOperator === assumeTrue && everyType(valueType, function (t) { return !(t.flags & (3 /* AnyOrUnknown */ | nullableFlags)); }); + return removeNullable ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; } function narrowTypeByEquality(type, operator, value, assumeTrue) { if (type.flags & 1 /* Any */) { @@ -55103,10 +55120,6 @@ var ts; var assignmentKind = ts.getAssignmentTargetKind(node); var apparentType = getApparentType(assignmentKind !== 0 /* None */ || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType); if (ts.isPrivateIdentifier(right)) { - if (ts.isOptionalChain(node)) { - grammarErrorOnNode(right, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); - return anyType; - } checkExternalEmitHelpers(node, 262144 /* ClassPrivateFieldGet */); } var isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType; @@ -63351,7 +63364,7 @@ var ts; } if (isInstancePropertyWithoutInitializer(member)) { var propName = member.name; - if (ts.isIdentifier(propName)) { + if (ts.isIdentifier(propName) || ts.isPrivateIdentifier(propName)) { var type = getTypeOfSymbol(getSymbolOfNode(member)); if (!(type.flags & 3 /* AnyOrUnknown */ || getFalsyFlags(type) & 32768 /* Undefined */)) { if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) { @@ -66588,28 +66601,30 @@ var ts; default: throw ts.Debug.assertNever(prop, "Unexpected syntax kind:" + prop.kind); } - var effectiveName = ts.getPropertyNameForPropertyNameNode(name); - if (effectiveName === undefined) { - continue; - } - var existingKind = seen.get(effectiveName); - if (!existingKind) { - seen.set(effectiveName, currentKind); - } - else { - if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { - grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + if (!inDestructuring) { + var effectiveName = ts.getPropertyNameForPropertyNameNode(name); + if (effectiveName === undefined) { + continue; } - else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { - if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { - seen.set(effectiveName, currentKind | existingKind); - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } + var existingKind = seen.get(effectiveName); + if (!existingKind) { + seen.set(effectiveName, currentKind); } else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { + grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + } + else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { + if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { + seen.set(effectiveName, currentKind | existingKind); + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } } } } @@ -89865,8 +89880,11 @@ var ts; var ts; (function (ts) { function getDeclarationDiagnostics(host, resolver, file) { + if (file && ts.isJsonSourceFile(file)) { + return []; // No declaration diagnostics for json for now + } var compilerOptions = host.getCompilerOptions(); - var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : host.getSourceFiles(), [transformDeclarations], /*allowDtsFiles*/ false); + var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : ts.filter(host.getSourceFiles(), ts.isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false); return result.diagnostics; } ts.getDeclarationDiagnostics = getDeclarationDiagnostics; @@ -91642,12 +91660,13 @@ var ts; } else { var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); + var isJsonFile = ts.isJsonSourceFile(sourceFile); // If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it - var isJsonEmittedToSameLocation = ts.isJsonSourceFile(sourceFile) && + var isJsonEmittedToSameLocation = isJsonFile && ts.comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === 0 /* EqualTo */; var jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath; var sourceMapFilePath = !jsFilePath || ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); - var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; + var declarationFilePath = (forceDtsPaths || (ts.getEmitDeclarations(options) && !isJsonFile)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, buildInfoPath: undefined }; } @@ -91688,7 +91707,7 @@ var ts; } /* @internal */ function getOutputDeclarationFileName(inputFileName, configFile, ignoreCase) { - ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */)); + ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(inputFileName, ".json" /* Json */)); return ts.changeExtension(getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir), ".d.ts" /* Dts */); } ts.getOutputDeclarationFileName = getOutputDeclarationFileName; @@ -91918,12 +91937,13 @@ var ts; return; } var sourceFiles = ts.isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles; + var filesForEmit = forceDtsEmit ? sourceFiles : ts.filter(sourceFiles, ts.isSourceFileNotJson); // Setup and perform the transformation to retrieve declarations from the input files - var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(sourceFiles, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : sourceFiles; + var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(filesForEmit, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit; if (emitOnlyDtsFiles && !ts.getEmitDeclarations(compilerOptions)) { // Checker wont collect the linked aliases since thats only done when declaration is enabled. // Do that here when emitting only dts files - sourceFiles.forEach(collectLinkedAliases); + filesForEmit.forEach(collectLinkedAliases); } var declarationTransform = ts.transformNodes(resolver, host, compilerOptions, inputListOrBundle, declarationTransformers, /*allowDtsFiles*/ false); if (ts.length(declarationTransform.diagnostics)) { @@ -97210,7 +97230,7 @@ var ts; else if (ts.getEmitModuleKind(parsedRef.commandLine.options) === ts.ModuleKind.None) { for (var _c = 0, _d = parsedRef.commandLine.fileNames; _c < _d.length; _c++) { var fileName = _d[_c]; - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { processSourceFile(ts.getOutputDeclarationFileName(fileName, parsedRef.commandLine, !host.useCaseSensitiveFileNames()), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined); } } @@ -98635,8 +98655,8 @@ var ts; return referencedProject && getProjectReferenceOutputName(referencedProject, fileName); } function getProjectReferenceRedirectProject(fileName) { - // Ignore dts - if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + // Ignore dts or any json files + if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) || ts.fileExtensionIs(fileName, ".json" /* Json */)) { return undefined; } // If this file is produced by a referenced project, we need to rewrite it to @@ -98690,7 +98710,7 @@ var ts; } else { ts.forEach(resolvedRef.commandLine.fileNames, function (fileName) { - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { var outputDts = ts.getOutputDeclarationFileName(fileName, resolvedRef.commandLine, host.useCaseSensitiveFileNames()); mapFromToProjectReferenceRedirectSource.set(toPath(outputDts), fileName); } @@ -110576,7 +110596,7 @@ var ts; switch (contextToken.kind) { case 27 /* CommaToken */: return containingNodeKind === 242 /* VariableDeclaration */ || - containingNodeKind === 243 /* VariableDeclarationList */ || + isVariableDeclarationListButNotTypeArgument(contextToken) || containingNodeKind === 225 /* VariableStatement */ || containingNodeKind === 248 /* EnumDeclaration */ || // enum a { foo, | isFunctionLikeButNotConstructor(containingNodeKind) || @@ -110687,6 +110707,10 @@ var ts; } return false; } + function isVariableDeclarationListButNotTypeArgument(node) { + return node.parent.kind === 243 /* VariableDeclarationList */ + && !ts.isPossiblyTypeArgumentPosition(node, sourceFile, typeChecker); + } /** * Filters out completion suggestions for named imports or exports. * diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index ec86a833529..e4aadbe0bc8 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -79,8 +79,8 @@ var __extends = (this && this.__extends) || (function () { })(); var ts; (function (ts) { - // WARNING: The script `configureNightly.ts` uses a regexp to parse out these values. - // If changing the text in this section, be sure to test `configureNightly` too. + // WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values. + // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.8"; /** The version of the TypeScript compiler release */ ts.version = ts.versionMajorMinor + ".0-beta"; @@ -7181,6 +7181,7 @@ var ts; The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access: diag(2779, ts.DiagnosticCategory.Error, "The_left_hand_side_of_an_assignment_expression_may_not_be_an_optional_property_access_2779", "The left-hand side of an assignment expression may not be an optional property access."), The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access: diag(2780, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_in_statement_may_not_be_an_optional_property_access_2780", "The left-hand side of a 'for...in' statement may not be an optional property access."), The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access: diag(2781, ts.DiagnosticCategory.Error, "The_left_hand_side_of_a_for_of_statement_may_not_be_an_optional_property_access_2781", "The left-hand side of a 'for...of' statement may not be an optional property access."), + _0_needs_an_explicit_type_annotation: diag(2782, ts.DiagnosticCategory.Message, "_0_needs_an_explicit_type_annotation_2782", "'{0}' needs an explicit type annotation."), Import_declaration_0_is_using_private_name_1: diag(4000, ts.DiagnosticCategory.Error, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."), Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."), Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, ts.DiagnosticCategory.Error, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."), @@ -14082,6 +14083,10 @@ var ts; return !!node && !!(node.flags & 33554432 /* JsonFile */); } ts.isInJsonFile = isInJsonFile; + function isSourceFileNotJson(file) { + return !isJsonSourceFile(file); + } + ts.isSourceFileNotJson = isSourceFileNotJson; function isInJSDoc(node) { return !!node && !!(node.flags & 4194304 /* JSDoc */); } @@ -22244,10 +22249,12 @@ var ts; var propertyAccess = createNode(194 /* PropertyAccessExpression */, expression.pos); propertyAccess.expression = expression; propertyAccess.questionDotToken = questionDotToken; - // checker will error on private identifiers in optional chains, so don't have to catch them here propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true); if (questionDotToken || expression.flags & 32 /* OptionalChain */) { propertyAccess.flags |= 32 /* OptionalChain */; + if (ts.isPrivateIdentifier(propertyAccess.name)) { + parseErrorAtRange(propertyAccess.name, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); + } } return finishNode(propertyAccess); } @@ -31298,7 +31305,7 @@ var ts; ElementKind[ElementKind["Property"] = 1] = "Property"; ElementKind[ElementKind["Accessor"] = 2] = "Accessor"; })(ElementKind || (ElementKind = {})); - if (inStrictMode) { + if (inStrictMode && !ts.isAssignmentTarget(node)) { var seen = ts.createUnderscoreEscapedMap(); for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; @@ -37703,6 +37710,9 @@ var ts; /*decorators*/ undefined, indexInfo.isReadonly ? [ts.createToken(138 /* ReadonlyKeyword */)] : undefined, [indexingParameter], typeNode); } function signatureToSignatureDeclarationHelper(signature, kind, context) { + var suppressAny = context.flags & 256 /* SuppressAnyReturnType */; + if (suppressAny) + context.flags &= ~256 /* SuppressAnyReturnType */; // suppress only toplevel `any`s var typeParameters; var typeArguments; if (context.flags & 32 /* WriteTypeArgumentsOfSignature */ && signature.target && signature.mapper && signature.target.typeParameters) { @@ -37730,15 +37740,12 @@ var ts; } else { var returnType = getReturnTypeOfSignature(signature); - returnTypeNode = returnType && typeToTypeNodeHelper(returnType, context); - } - if (context.flags & 256 /* SuppressAnyReturnType */) { - if (returnTypeNode && returnTypeNode.kind === 125 /* AnyKeyword */) { - returnTypeNode = undefined; + if (returnType && !(suppressAny && isTypeAny(returnType))) { + returnTypeNode = typeToTypeNodeHelper(returnType, context); + } + else if (!suppressAny) { + returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } - } - else if (!returnTypeNode) { - returnTypeNode = ts.createKeywordTypeNode(125 /* AnyKeyword */); } context.approximateLength += 3; // Usually a signature contributes a few more characters than this, but 3 is the minimum return ts.createSignatureDeclaration(kind, typeParameters, parameters, returnTypeNode, typeArguments); @@ -46712,7 +46719,8 @@ var ts; return false; } function isEmptyResolvedType(t) { - return t.properties.length === 0 && + return t !== anyFunctionType && + t.properties.length === 0 && t.callSignatures.length === 0 && t.constructSignatures.length === 0 && !t.stringIndexInfo && @@ -51116,7 +51124,7 @@ var ts; return getTypeOfSymbol(symbol); } if (diagnostic && symbol.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_is_declared_here, symbolToString(symbol))); + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(symbol.valueDeclaration, ts.Diagnostics._0_needs_an_explicit_type_annotation, symbolToString(symbol))); } } } @@ -51817,13 +51825,22 @@ var ts; return type; } function narrowTypeByOptionalChainContainment(type, operator, value, assumeTrue) { - // We are in a branch of obj?.foo === value or obj?.foo !== value. We remove undefined and null from - // the type of obj if (a) the operator is === and the type of value doesn't include undefined or (b) the - // operator is !== and the type of value is undefined. - var effectiveTrue = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */ ? assumeTrue : !assumeTrue; - var doubleEquals = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */; - var valueNonNullish = !(getTypeFacts(getTypeOfExpression(value)) & (doubleEquals ? 262144 /* EQUndefinedOrNull */ : 65536 /* EQUndefined */)); - return effectiveTrue === valueNonNullish ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; + // We are in a branch of obj?.foo === value (or any one of the other equality operators). We narrow obj as follows: + // When operator is === and type of value excludes undefined, null and undefined is removed from type of obj in true branch. + // When operator is !== and type of value excludes undefined, null and undefined is removed from type of obj in false branch. + // When operator is == and type of value excludes null and undefined, null and undefined is removed from type of obj in true branch. + // When operator is != and type of value excludes null and undefined, null and undefined is removed from type of obj in false branch. + // When operator is === and type of value is undefined, null and undefined is removed from type of obj in false branch. + // When operator is !== and type of value is undefined, null and undefined is removed from type of obj in true branch. + // When operator is == and type of value is null or undefined, null and undefined is removed from type of obj in false branch. + // When operator is != and type of value is null or undefined, null and undefined is removed from type of obj in true branch. + var equalsOperator = operator === 34 /* EqualsEqualsToken */ || operator === 36 /* EqualsEqualsEqualsToken */; + var nullableFlags = operator === 34 /* EqualsEqualsToken */ || operator === 35 /* ExclamationEqualsToken */ ? 98304 /* Nullable */ : 32768 /* Undefined */; + var valueType = getTypeOfExpression(value); + // Note that we include any and unknown in the exclusion test because their domain includes null and undefined. + var removeNullable = equalsOperator !== assumeTrue && everyType(valueType, function (t) { return !!(t.flags & nullableFlags); }) || + equalsOperator === assumeTrue && everyType(valueType, function (t) { return !(t.flags & (3 /* AnyOrUnknown */ | nullableFlags)); }); + return removeNullable ? getTypeWithFacts(type, 2097152 /* NEUndefinedOrNull */) : type; } function narrowTypeByEquality(type, operator, value, assumeTrue) { if (type.flags & 1 /* Any */) { @@ -54953,10 +54970,6 @@ var ts; var assignmentKind = ts.getAssignmentTargetKind(node); var apparentType = getApparentType(assignmentKind !== 0 /* None */ || isMethodAccessForCall(node) ? getWidenedType(leftType) : leftType); if (ts.isPrivateIdentifier(right)) { - if (ts.isOptionalChain(node)) { - grammarErrorOnNode(right, ts.Diagnostics.An_optional_chain_cannot_contain_private_identifiers); - return anyType; - } checkExternalEmitHelpers(node, 262144 /* ClassPrivateFieldGet */); } var isAnyLike = isTypeAny(apparentType) || apparentType === silentNeverType; @@ -63201,7 +63214,7 @@ var ts; } if (isInstancePropertyWithoutInitializer(member)) { var propName = member.name; - if (ts.isIdentifier(propName)) { + if (ts.isIdentifier(propName) || ts.isPrivateIdentifier(propName)) { var type = getTypeOfSymbol(getSymbolOfNode(member)); if (!(type.flags & 3 /* AnyOrUnknown */ || getFalsyFlags(type) & 32768 /* Undefined */)) { if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) { @@ -66438,28 +66451,30 @@ var ts; default: throw ts.Debug.assertNever(prop, "Unexpected syntax kind:" + prop.kind); } - var effectiveName = ts.getPropertyNameForPropertyNameNode(name); - if (effectiveName === undefined) { - continue; - } - var existingKind = seen.get(effectiveName); - if (!existingKind) { - seen.set(effectiveName, currentKind); - } - else { - if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { - grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + if (!inDestructuring) { + var effectiveName = ts.getPropertyNameForPropertyNameNode(name); + if (effectiveName === undefined) { + continue; } - else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { - if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { - seen.set(effectiveName, currentKind | existingKind); - } - else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); - } + var existingKind = seen.get(effectiveName); + if (!existingKind) { + seen.set(effectiveName, currentKind); } else { - return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + if ((currentKind & 12 /* PropertyAssignmentOrMethod */) && (existingKind & 12 /* PropertyAssignmentOrMethod */)) { + grammarErrorOnNode(name, ts.Diagnostics.Duplicate_identifier_0, ts.getTextOfNode(name)); + } + else if ((currentKind & 3 /* GetOrSetAccessor */) && (existingKind & 3 /* GetOrSetAccessor */)) { + if (existingKind !== 3 /* GetOrSetAccessor */ && currentKind !== existingKind) { + seen.set(effectiveName, currentKind | existingKind); + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + } + } + else { + return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + } } } } @@ -89715,8 +89730,11 @@ var ts; var ts; (function (ts) { function getDeclarationDiagnostics(host, resolver, file) { + if (file && ts.isJsonSourceFile(file)) { + return []; // No declaration diagnostics for json for now + } var compilerOptions = host.getCompilerOptions(); - var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : host.getSourceFiles(), [transformDeclarations], /*allowDtsFiles*/ false); + var result = ts.transformNodes(resolver, host, compilerOptions, file ? [file] : ts.filter(host.getSourceFiles(), ts.isSourceFileNotJson), [transformDeclarations], /*allowDtsFiles*/ false); return result.diagnostics; } ts.getDeclarationDiagnostics = getDeclarationDiagnostics; @@ -91492,12 +91510,13 @@ var ts; } else { var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options)); + var isJsonFile = ts.isJsonSourceFile(sourceFile); // If json file emits to the same location skip writing it, if emitDeclarationOnly skip writing it - var isJsonEmittedToSameLocation = ts.isJsonSourceFile(sourceFile) && + var isJsonEmittedToSameLocation = isJsonFile && ts.comparePaths(sourceFile.fileName, ownOutputFilePath, host.getCurrentDirectory(), !host.useCaseSensitiveFileNames()) === 0 /* EqualTo */; var jsFilePath = options.emitDeclarationOnly || isJsonEmittedToSameLocation ? undefined : ownOutputFilePath; var sourceMapFilePath = !jsFilePath || ts.isJsonSourceFile(sourceFile) ? undefined : getSourceMapFilePath(jsFilePath, options); - var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; + var declarationFilePath = (forceDtsPaths || (ts.getEmitDeclarations(options) && !isJsonFile)) ? ts.getDeclarationEmitOutputFilePath(sourceFile.fileName, host) : undefined; var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined; return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, buildInfoPath: undefined }; } @@ -91538,7 +91557,7 @@ var ts; } /* @internal */ function getOutputDeclarationFileName(inputFileName, configFile, ignoreCase) { - ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */)); + ts.Debug.assert(!ts.fileExtensionIs(inputFileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(inputFileName, ".json" /* Json */)); return ts.changeExtension(getOutputPathWithoutChangingExt(inputFileName, configFile, ignoreCase, configFile.options.declarationDir || configFile.options.outDir), ".d.ts" /* Dts */); } ts.getOutputDeclarationFileName = getOutputDeclarationFileName; @@ -91768,12 +91787,13 @@ var ts; return; } var sourceFiles = ts.isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles; + var filesForEmit = forceDtsEmit ? sourceFiles : ts.filter(sourceFiles, ts.isSourceFileNotJson); // Setup and perform the transformation to retrieve declarations from the input files - var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(sourceFiles, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : sourceFiles; + var inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [ts.createBundle(filesForEmit, !ts.isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit; if (emitOnlyDtsFiles && !ts.getEmitDeclarations(compilerOptions)) { // Checker wont collect the linked aliases since thats only done when declaration is enabled. // Do that here when emitting only dts files - sourceFiles.forEach(collectLinkedAliases); + filesForEmit.forEach(collectLinkedAliases); } var declarationTransform = ts.transformNodes(resolver, host, compilerOptions, inputListOrBundle, declarationTransformers, /*allowDtsFiles*/ false); if (ts.length(declarationTransform.diagnostics)) { @@ -97060,7 +97080,7 @@ var ts; else if (ts.getEmitModuleKind(parsedRef.commandLine.options) === ts.ModuleKind.None) { for (var _c = 0, _d = parsedRef.commandLine.fileNames; _c < _d.length; _c++) { var fileName = _d[_c]; - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { processSourceFile(ts.getOutputDeclarationFileName(fileName, parsedRef.commandLine, !host.useCaseSensitiveFileNames()), /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined); } } @@ -98485,8 +98505,8 @@ var ts; return referencedProject && getProjectReferenceOutputName(referencedProject, fileName); } function getProjectReferenceRedirectProject(fileName) { - // Ignore dts - if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + // Ignore dts or any json files + if (!resolvedProjectReferences || !resolvedProjectReferences.length || ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) || ts.fileExtensionIs(fileName, ".json" /* Json */)) { return undefined; } // If this file is produced by a referenced project, we need to rewrite it to @@ -98540,7 +98560,7 @@ var ts; } else { ts.forEach(resolvedRef.commandLine.fileNames, function (fileName) { - if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */)) { + if (!ts.fileExtensionIs(fileName, ".d.ts" /* Dts */) && !ts.fileExtensionIs(fileName, ".json" /* Json */)) { var outputDts = ts.getOutputDeclarationFileName(fileName, resolvedRef.commandLine, host.useCaseSensitiveFileNames()); mapFromToProjectReferenceRedirectSource.set(toPath(outputDts), fileName); }