Skip to content

Commit

Permalink
Merge branch master into type-only-2
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Jan 21, 2020
2 parents 8b4c235 + 38eccba commit be5f50f
Show file tree
Hide file tree
Showing 184 changed files with 4,959 additions and 1,506 deletions.
8 changes: 1 addition & 7 deletions lib/cancellationToken.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/ja/diagnosticMessages.generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
"Generic_type_0_requires_1_type_argument_s_2314": "ジェネリック型 '{0}' には {1} 個の型引数が必要です。",
"Generic_type_0_requires_between_1_and_2_type_arguments_2707": "ジェネリック型 '{0}' には、{1} 個から {2} 個までの型引数が必要です。",
"Generic_type_instantiation_is_excessively_deep_and_possibly_infinite_2550": "ジェネリック型のインスタンス化は非常に深く、無限である可能性があります。",
"Getter_and_setter_accessors_do_not_agree_in_visibility_2379": "ゲッターおよびセッターで表示が許可されていません",
"Getter_and_setter_accessors_do_not_agree_in_visibility_2379": "ゲッターおよびセッターでの表示が許可されていません",
"Global_module_exports_may_only_appear_at_top_level_1316": "グローバル モジュールのエクスポートは最上位レベルにのみ出現可能です。",
"Global_module_exports_may_only_appear_in_declaration_files_1315": "グローバル モジュールのエクスポートは宣言ファイルにのみ出現可能です。",
"Global_module_exports_may_only_appear_in_module_files_1314": "グローバル モジュールのエクスポートはモジュール ファイルにのみ出現可能です。",
Expand Down
650 changes: 325 additions & 325 deletions lib/lib.esnext.bigint.d.ts

Large diffs are not rendered by default.

132 changes: 80 additions & 52 deletions lib/tsc.js

Large diffs are not rendered by default.

492 changes: 343 additions & 149 deletions lib/tsserver.js

Large diffs are not rendered by default.

492 changes: 343 additions & 149 deletions lib/tsserverlibrary.js

Large diffs are not rendered by default.

468 changes: 334 additions & 134 deletions lib/typescript.js

Large diffs are not rendered by default.

468 changes: 334 additions & 134 deletions lib/typescriptServices.js

Large diffs are not rendered by default.

156 changes: 93 additions & 63 deletions lib/typingsInstaller.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/zh-tw/diagnosticMessages.generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@
"Generic_type_0_requires_1_type_argument_s_2314": "泛型類型 '{0}' 需要 {1} 個型別引數。",
"Generic_type_0_requires_between_1_and_2_type_arguments_2707": "泛型型別 '{0}' 需要介於 {1} 和 {2} 之間的型別引數。",
"Generic_type_instantiation_is_excessively_deep_and_possibly_infinite_2550": "泛型類型具現化的深度過深,而且可能是無限深。",
"Getter_and_setter_accessors_do_not_agree_in_visibility_2379": "getter 和 setter 存取子的可視性不符",
"Getter_and_setter_accessors_do_not_agree_in_visibility_2379": "getter 和 setter 存取子的可見度不符",
"Global_module_exports_may_only_appear_at_top_level_1316": "全域模組匯出只能顯示在最上層。",
"Global_module_exports_may_only_appear_in_declaration_files_1315": "全域模組匯出只能顯示在宣告檔案中。",
"Global_module_exports_may_only_appear_in_module_files_1314": "全域模組匯出只能顯示在模組檔案中。",
Expand Down
15 changes: 8 additions & 7 deletions src/cancellationToken/cancellationToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ interface ServerCancellationToken {
}

function pipeExists(name: string): boolean {
try {
fs.statSync(name);
return true;
}
catch (e) {
return false;
}
// Unlike statSync, existsSync doesn't throw an exception if the target doesn't exist.
// A comment in the node code suggests they're stuck with that decision for back compat
// (https://github.com/nodejs/node/blob/9da241b600182a9ff400f6efc24f11a6303c27f7/lib/fs.js#L222).
// Caveat: If a named pipe does exist, the first call to existsSync will return true, as for
// statSync. Subsequent calls will return false, whereas statSync would throw an exception
// indicating that the pipe was busy. The difference is immaterial, since our statSync
// implementation returned false from its catch block.
return fs.existsSync(name);
}

function createCancellationToken(args: string[]): ServerCancellationToken {
Expand Down
17 changes: 10 additions & 7 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ namespace ts {
case SyntaxKind.ThisKeyword:
case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.ElementAccessExpression:
return isNarrowableReference(expr);
return containsNarrowableReference(expr);
case SyntaxKind.CallExpression:
return hasNarrowableArgument(<CallExpression>expr);
case SyntaxKind.ParenthesizedExpression:
Expand All @@ -879,20 +879,23 @@ namespace ts {
function isNarrowableReference(expr: Expression): boolean {
return expr.kind === SyntaxKind.Identifier || expr.kind === SyntaxKind.ThisKeyword || expr.kind === SyntaxKind.SuperKeyword ||
(isPropertyAccessExpression(expr) || isNonNullExpression(expr) || isParenthesizedExpression(expr)) && isNarrowableReference(expr.expression) ||
isElementAccessExpression(expr) && isStringOrNumericLiteralLike(expr.argumentExpression) && isNarrowableReference(expr.expression) ||
isOptionalChain(expr);
isElementAccessExpression(expr) && isStringOrNumericLiteralLike(expr.argumentExpression) && isNarrowableReference(expr.expression);
}

function containsNarrowableReference(expr: Expression): boolean {
return isNarrowableReference(expr) || isOptionalChain(expr) && containsNarrowableReference(expr.expression);
}

function hasNarrowableArgument(expr: CallExpression) {
if (expr.arguments) {
for (const argument of expr.arguments) {
if (isNarrowableReference(argument)) {
if (containsNarrowableReference(argument)) {
return true;
}
}
}
if (expr.expression.kind === SyntaxKind.PropertyAccessExpression &&
isNarrowableReference((<PropertyAccessExpression>expr.expression).expression)) {
containsNarrowableReference((<PropertyAccessExpression>expr.expression).expression)) {
return true;
}
return false;
Expand All @@ -909,7 +912,7 @@ namespace ts {
function isNarrowingBinaryExpression(expr: BinaryExpression) {
switch (expr.operatorToken.kind) {
case SyntaxKind.EqualsToken:
return isNarrowableReference(expr.left);
return containsNarrowableReference(expr.left);
case SyntaxKind.EqualsEqualsToken:
case SyntaxKind.ExclamationEqualsToken:
case SyntaxKind.EqualsEqualsEqualsToken:
Expand Down Expand Up @@ -938,7 +941,7 @@ namespace ts {
return isNarrowableOperand((<BinaryExpression>expr).right);
}
}
return isNarrowableReference(expr);
return containsNarrowableReference(expr);
}

function createBranchLabel(): FlowLabel {
Expand Down
68 changes: 53 additions & 15 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ namespace ts {

const emptySymbols = createSymbolTable();
const identityMapper: (type: Type) => Type = identity;
const arrayVariances = [VarianceFlags.Covariant];

const compilerOptions = host.getCompilerOptions();
const languageVersion = getEmitScriptTarget(compilerOptions);
Expand Down Expand Up @@ -570,9 +571,12 @@ namespace ts {
isArrayLikeType,
isTypeInvalidDueToUnionDiscriminant,
getAllPossiblePropertiesOfTypes,
getSuggestionForNonexistentProperty: (node, type) => getSuggestionForNonexistentProperty(node, type),
getSuggestedSymbolForNonexistentProperty,
getSuggestionForNonexistentProperty,
getSuggestedSymbolForNonexistentSymbol: (location, name, meaning) => getSuggestedSymbolForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
getSuggestionForNonexistentSymbol: (location, name, meaning) => getSuggestionForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
getSuggestionForNonexistentExport: (node, target) => getSuggestionForNonexistentExport(node, target),
getSuggestedSymbolForNonexistentModule,
getSuggestionForNonexistentExport,
getBaseConstraintOfType,
getDefaultFromTypeParameter: type => type && type.flags & TypeFlags.TypeParameter ? getDefaultFromTypeParameter(type as TypeParameter) : undefined,
resolveName(name, location, meaning, excludeGlobals) {
Expand Down Expand Up @@ -2372,7 +2376,7 @@ namespace ts {
}
}
else {
if (moduleSymbol.exports && moduleSymbol.exports.has(InternalSymbolName.Default)) {
if (moduleSymbol.exports?.has(InternalSymbolName.Default)) {
error(
name,
Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead,
Expand All @@ -2381,7 +2385,7 @@ namespace ts {
);
}
else {
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
reportNonExportedMember(name, declarationName, moduleSymbol, moduleName);
}
}
}
Expand All @@ -2390,6 +2394,27 @@ namespace ts {
}
}

function reportNonExportedMember(name: Identifier, declarationName: string, moduleSymbol: Symbol, moduleName: string): void {
const localSymbol = moduleSymbol.valueDeclaration.locals?.get(name.escapedText);
const exports = moduleSymbol.exports;

if (localSymbol) {
const exportedSymbol = exports && !exports.has(InternalSymbolName.ExportEquals)
? find(symbolsToArray(exports), symbol => !!getSymbolIfSameReference(symbol, localSymbol))
: undefined;
const diagnostic = exportedSymbol
? error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_exported_as_2, moduleName, declarationName, symbolToString(exportedSymbol))
: error(name, Diagnostics.Module_0_declares_1_locally_but_it_is_not_exported, moduleName, declarationName);

addRelatedInfo(diagnostic,
createDiagnosticForNode(localSymbol.valueDeclaration, Diagnostics._0_is_declared_here, declarationName)
);
}
else {
error(name, Diagnostics.Module_0_has_no_exported_member_1, moduleName, declarationName);
}
}

function getTargetOfImportSpecifier(node: ImportSpecifier, dontResolveAlias: boolean): Symbol | undefined {
checkAliasDeclarationForTypeOnlyMarker(node);
return getExternalModuleMember(node.parent.parent.parent, node, dontResolveAlias);
Expand Down Expand Up @@ -15371,6 +15396,9 @@ namespace ts {
source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
!(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
const variances = getAliasVariances(source.aliasSymbol);
if (variances === emptyArray) {
return Ternary.Maybe;
}
const varianceResult = relateVariances(source.aliasTypeArguments, target.aliasTypeArguments, variances, intersectionState);
if (varianceResult !== undefined) {
return varianceResult;
Expand Down Expand Up @@ -15567,6 +15595,12 @@ namespace ts {
// type references (which are intended by be compared structurally). Obtain the variance
// information for the type parameters and relate the type arguments accordingly.
const variances = getVariances((<TypeReference>source).target);
// We return Ternary.Maybe for a recursive invocation of getVariances (signalled by emptyArray). This
// effectively means we measure variance only from type parameter occurrences that aren't nested in
// recursive instantiations of the generic type.
if (variances === emptyArray) {
return Ternary.Maybe;
}
const varianceResult = relateVariances(getTypeArguments(<TypeReference>source), getTypeArguments(<TypeReference>target), variances, intersectionState);
if (varianceResult !== undefined) {
return varianceResult;
Expand Down Expand Up @@ -16386,8 +16420,7 @@ namespace ts {
// a digest of the type comparisons that occur for each type argument when instantiations of the
// generic type are structurally compared. We infer the variance information by comparing
// instantiations of the generic type for type arguments with known relations. The function
// returns the emptyArray singleton if we're not in strictFunctionTypes mode or if the function
// has been invoked recursively for the given generic type.
// returns the emptyArray singleton when invoked recursively for the given generic type.
function getVariancesWorker<TCache extends { variances?: VarianceFlags[] }>(typeParameters: readonly TypeParameter[] = emptyArray, cache: TCache, createMarkerType: (input: TCache, param: TypeParameter, marker: Type) => Type): VarianceFlags[] {
let variances = cache.variances;
if (!variances) {
Expand Down Expand Up @@ -16430,9 +16463,9 @@ namespace ts {
}

function getVariances(type: GenericType): VarianceFlags[] {
// Arrays and tuples are known to be covariant, no need to spend time computing this (emptyArray implies covariance for all parameters)
// Arrays and tuples are known to be covariant, no need to spend time computing this.
if (type === globalArrayType || type === globalReadonlyArrayType || type.objectFlags & ObjectFlags.Tuple) {
return emptyArray;
return arrayVariances;
}
return getVariancesWorker(type.typeParameters, type, getMarkerTypeReference);
}
Expand Down Expand Up @@ -26626,13 +26659,18 @@ namespace ts {
if (!(node.flags & NodeFlags.AwaitContext)) {
if (isTopLevelAwait(node)) {
const sourceFile = getSourceFileOfNode(node);
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) ||
languageVersion < ScriptTarget.ES2017 ||
!isEffectiveExternalModule(sourceFile, compilerOptions)) {
if (!hasParseDiagnostics(sourceFile)) {
const span = getSpanOfTokenAtPosition(sourceFile, node.pos);
if (!hasParseDiagnostics(sourceFile)) {
let span: TextSpan | undefined;
if (!isEffectiveExternalModule(sourceFile, compilerOptions)) {
if (!span) span = getSpanOfTokenAtPosition(sourceFile, node.pos);
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module);
diagnostics.add(diagnostic);
}
if ((moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System) || languageVersion < ScriptTarget.ES2017) {
span = getSpanOfTokenAtPosition(sourceFile, node.pos);
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length,
Diagnostics.await_outside_of_an_async_function_is_only_allowed_at_the_top_level_of_a_module_when_module_is_esnext_or_system_and_target_is_es2017_or_higher);
Diagnostics.Top_level_await_expressions_are_only_allowed_when_the_module_option_is_set_to_esnext_or_system_and_the_target_option_is_set_to_es2017_or_higher);
diagnostics.add(diagnostic);
}
}
Expand All @@ -26642,7 +26680,7 @@ namespace ts {
const sourceFile = getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
const span = getSpanOfTokenAtPosition(sourceFile, node.pos);
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.await_expression_is_only_allowed_within_an_async_function);
const diagnostic = createFileDiagnostic(sourceFile, span.start, span.length, Diagnostics.await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules);
const func = getContainingFunction(node);
if (func && func.kind !== SyntaxKind.Constructor && (getFunctionFlags(func) & FunctionFlags.Async) === 0) {
const relatedInfo = createDiagnosticForNode(func, Diagnostics.Did_you_mean_to_mark_this_function_as_async);
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ namespace ts {
error: ImportsNotUsedAsValues.Error
}),
affectsEmit: true,
affectsSemanticDiagnostics: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types
},
Expand Down Expand Up @@ -742,12 +743,15 @@ namespace ts {
{
name: "experimentalDecorators",
type: "boolean",
affectsSemanticDiagnostics: true,
category: Diagnostics.Experimental_Options,
description: Diagnostics.Enables_experimental_support_for_ES7_decorators
},
{
name: "emitDecoratorMetadata",
type: "boolean",
affectsSemanticDiagnostics: true,
affectsEmit: true,
category: Diagnostics.Experimental_Options,
description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators
},
Expand All @@ -762,6 +766,7 @@ namespace ts {
{
name: "resolveJsonModule",
type: "boolean",
affectsModuleResolution: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Include_modules_imported_with_json_extension
},
Expand Down Expand Up @@ -946,6 +951,7 @@ namespace ts {
{
name: "forceConsistentCasingInFileNames",
type: "boolean",
affectsModuleResolution: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file
},
Expand All @@ -967,6 +973,7 @@ namespace ts {
name: "useDefineForClassFields",
type: "boolean",
affectsSemanticDiagnostics: true,
affectsEmit: true,
category: Diagnostics.Advanced_Options,
description: Diagnostics.Emit_class_fields_with_Define_instead_of_Set,
},
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,11 @@ namespace ts {
return result;
}

/**
* Creates a new object by adding the own properties of `second`, then the own properties of `first`.
*
* NOTE: This means that if a property exists in both `first` and `second`, the property in `first` will be chosen.
*/
export function extend<T1, T2>(first: T1, second: T2): T1 & T2 {
const result: T1 & T2 = <any>{};
for (const id in second) {
Expand Down
Loading

0 comments on commit be5f50f

Please sign in to comment.