mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Merge branch 'master' into referencesDogfood_1
This commit is contained in:
commit
df95de3231
120 files changed
+3082
-1867
No files matched your search
+19
-7
@@ -4170,14 +4170,17 @@ namespace ts {
|
||||
else {
|
||||
// Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form)
|
||||
const name = declaration.propertyName || <Identifier>declaration.name;
|
||||
if (isComputedNonLiteralName(name)) {
|
||||
// computed properties with non-literal names are treated as 'any'
|
||||
const isLate = isLateBindableName(name);
|
||||
const isWellKnown = isComputedPropertyName(name) && isWellKnownSymbolSyntactically(name.expression);
|
||||
if (!isLate && !isWellKnown && isComputedNonLiteralName(name)) {
|
||||
return anyType;
|
||||
}
|
||||
|
||||
// Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
|
||||
// or otherwise the type of the string index signature.
|
||||
const text = getTextOfPropertyName(name);
|
||||
const text = isLate ? getLateBoundNameFromType(checkComputedPropertyName(name as ComputedPropertyName) as LiteralType | UniqueESSymbolType) :
|
||||
isWellKnown ? getPropertyNameForKnownSymbolName(idText(((name as ComputedPropertyName).expression as PropertyAccessExpression).name)) :
|
||||
getTextOfPropertyName(name);
|
||||
|
||||
// Relax null check on ambient destructuring parameters, since the parameters have no implementation and are just documentation
|
||||
if (strictNullChecks && declaration.flags & NodeFlags.Ambient && isParameterDeclaration(declaration)) {
|
||||
@@ -4363,7 +4366,7 @@ namespace ts {
|
||||
for (const declaration of symbol.declarations) {
|
||||
let declarationInConstructor = false;
|
||||
const expression = declaration.kind === SyntaxKind.BinaryExpression ? <BinaryExpression>declaration :
|
||||
declaration.kind === SyntaxKind.PropertyAccessExpression ? <BinaryExpression>getAncestor(declaration, SyntaxKind.BinaryExpression) :
|
||||
declaration.kind === SyntaxKind.PropertyAccessExpression ? cast(declaration.parent, isBinaryExpression) :
|
||||
undefined;
|
||||
|
||||
if (!expression) {
|
||||
@@ -13875,7 +13878,8 @@ namespace ts {
|
||||
const assignmentKind = getAssignmentTargetKind(node);
|
||||
|
||||
if (assignmentKind) {
|
||||
if (!(localOrExportSymbol.flags & SymbolFlags.Variable)) {
|
||||
if (!(localOrExportSymbol.flags & SymbolFlags.Variable) &&
|
||||
!(isInJavaScriptFile(node) && localOrExportSymbol.flags & SymbolFlags.ValueModule)) {
|
||||
error(node, Diagnostics.Cannot_assign_to_0_because_it_is_not_a_variable, symbolToString(symbol));
|
||||
return unknownType;
|
||||
}
|
||||
@@ -19086,6 +19090,9 @@ namespace ts {
|
||||
|
||||
const links = getNodeLinks(node);
|
||||
const type = getTypeOfSymbol(node.symbol);
|
||||
if (isTypeAny(type)) {
|
||||
return type;
|
||||
}
|
||||
|
||||
// Check if function expression is contextually typed and assign parameter types if so.
|
||||
if (!(links.flags & NodeCheckFlags.ContextChecked)) {
|
||||
@@ -19848,8 +19855,9 @@ namespace ts {
|
||||
// VarExpr = ValueExpr
|
||||
// requires VarExpr to be classified as a reference
|
||||
// A compound assignment furthermore requires VarExpr to be classified as a reference (section 4.1)
|
||||
// and the type of the non - compound operation to be assignable to the type of VarExpr.
|
||||
if (checkReferenceExpression(left, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)) {
|
||||
// and the type of the non-compound operation to be assignable to the type of VarExpr.
|
||||
if (checkReferenceExpression(left, Diagnostics.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access)
|
||||
&& (!isIdentifier(left) || unescapeLeadingUnderscores(left.escapedText) !== "exports")) {
|
||||
// to avoid cascading errors check assignability only if 'isReference' check succeeded and no errors were reported
|
||||
checkTypeAssignableTo(valueType, leftType, left, /*headMessage*/ undefined);
|
||||
}
|
||||
@@ -21867,6 +21875,10 @@ namespace ts {
|
||||
// and give a better error message when the host function mentions `arguments`
|
||||
// but the tag doesn't have an array type
|
||||
if (decl) {
|
||||
const i = getJSDocTags(decl).filter(isJSDocParameterTag).indexOf(node);
|
||||
if (i > -1 && i < decl.parameters.length && isBindingPattern(decl.parameters[i].name)) {
|
||||
return;
|
||||
}
|
||||
if (!containsArgumentsReference(decl)) {
|
||||
error(node.name,
|
||||
Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name,
|
||||
|
||||
@@ -1265,10 +1265,7 @@ namespace ts {
|
||||
});
|
||||
}
|
||||
|
||||
export function assign<T1 extends MapLike<{}>, T2, T3>(t: T1, arg1: T2, arg2: T3): T1 & T2 & T3;
|
||||
export function assign<T1 extends MapLike<{}>, T2>(t: T1, arg1: T2): T1 & T2;
|
||||
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]): any;
|
||||
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]) {
|
||||
export function assign<T extends object>(t: T, ...args: T[]) {
|
||||
for (const arg of args) {
|
||||
for (const p in arg) {
|
||||
if (hasProperty(arg, p)) {
|
||||
@@ -1724,6 +1721,10 @@ namespace ts {
|
||||
return compareComparableValues(a, b);
|
||||
}
|
||||
|
||||
export function min<T>(a: T, b: T, compare: Comparer<T>): T {
|
||||
return compare(a, b) === Comparison.LessThan ? a : b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare two strings using a case-insensitive ordinal comparison.
|
||||
*
|
||||
@@ -3119,8 +3120,8 @@ namespace ts {
|
||||
return (arg: T) => f(arg) && g(arg);
|
||||
}
|
||||
|
||||
export function or<T>(f: (arg: T) => boolean, g: (arg: T) => boolean) {
|
||||
return (arg: T) => f(arg) || g(arg);
|
||||
export function or<T>(f: (arg: T) => boolean, g: (arg: T) => boolean): (arg: T) => boolean {
|
||||
return arg => f(arg) || g(arg);
|
||||
}
|
||||
|
||||
export function assertTypeIsNever(_: never): void { } // tslint:disable-line no-empty
|
||||
|
||||
@@ -4161,5 +4161,9 @@
|
||||
"Convert all constructor functions to classes": {
|
||||
"category": "Message",
|
||||
"code": 95045
|
||||
},
|
||||
"Generate 'get' and 'set' accessors": {
|
||||
"category": "Message",
|
||||
"code": 95046
|
||||
}
|
||||
}
|
||||
@@ -7600,7 +7600,7 @@ namespace ts {
|
||||
const tripleSlashXMLCommentStartRegEx = /^\/\/\/\s*<(\S+)\s.*?\/>/im;
|
||||
const singleLinePragmaRegEx = /^\/\/\/?\s*@(\S+)\s*(.*)\s*$/im;
|
||||
function extractPragmas(pragmas: PragmaPsuedoMapEntry[], range: CommentRange, text: string) {
|
||||
const tripleSlash = tripleSlashXMLCommentStartRegEx.exec(text);
|
||||
const tripleSlash = range.kind === SyntaxKind.SingleLineCommentTrivia && tripleSlashXMLCommentStartRegEx.exec(text);
|
||||
if (tripleSlash) {
|
||||
const name = tripleSlash[1].toLowerCase() as keyof PragmaPsuedoMap; // Technically unsafe cast, but we do it so the below check to make it safe typechecks
|
||||
const pragma = commentPragmas[name] as PragmaDefinition;
|
||||
@@ -7637,15 +7637,17 @@ namespace ts {
|
||||
return;
|
||||
}
|
||||
|
||||
const singleLine = singleLinePragmaRegEx.exec(text);
|
||||
const singleLine = range.kind === SyntaxKind.SingleLineCommentTrivia && singleLinePragmaRegEx.exec(text);
|
||||
if (singleLine) {
|
||||
return addPragmaForMatch(pragmas, range, PragmaKindFlags.SingleLine, singleLine);
|
||||
}
|
||||
|
||||
const multiLinePragmaRegEx = /\s*@(\S+)\s*(.*)\s*$/gim; // Defined inline since it uses the "g" flag, which keeps a persistent index (for iterating)
|
||||
let multiLineMatch: RegExpExecArray;
|
||||
while (multiLineMatch = multiLinePragmaRegEx.exec(text)) {
|
||||
addPragmaForMatch(pragmas, range, PragmaKindFlags.MultiLine, multiLineMatch);
|
||||
if (range.kind === SyntaxKind.MultiLineCommentTrivia) {
|
||||
const multiLinePragmaRegEx = /\s*@(\S+)\s*(.*)\s*$/gim; // Defined inline since it uses the "g" flag, which keeps a persistent index (for iterating)
|
||||
let multiLineMatch: RegExpExecArray;
|
||||
while (multiLineMatch = multiLinePragmaRegEx.exec(text)) {
|
||||
addPragmaForMatch(pragmas, range, PragmaKindFlags.MultiLine, multiLineMatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -573,7 +573,6 @@ namespace ts {
|
||||
const packageIdToSourceFile = createMap<SourceFile>();
|
||||
// Maps from a SourceFile's `.path` to the name of the package it was imported with.
|
||||
let sourceFileToPackageName = createMap<string>();
|
||||
// See `sourceFileIsRedirectedTo`.
|
||||
let redirectTargetsSet = createMap<true>();
|
||||
|
||||
const filesByName = createMap<SourceFile | undefined>();
|
||||
|
||||
+3
-3
@@ -18,7 +18,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
let reportDiagnostic = createDiagnosticReporter(sys);
|
||||
function udpateReportDiagnostic(options: CompilerOptions) {
|
||||
function updateReportDiagnostic(options: CompilerOptions) {
|
||||
if (options.pretty) {
|
||||
reportDiagnostic = createDiagnosticReporter(sys, /*pretty*/ true);
|
||||
}
|
||||
@@ -107,7 +107,7 @@ namespace ts {
|
||||
const commandLineOptions = commandLine.options;
|
||||
if (configFileName) {
|
||||
const configParseResult = parseConfigFileWithSystem(configFileName, commandLineOptions, sys, reportDiagnostic);
|
||||
udpateReportDiagnostic(configParseResult.options);
|
||||
updateReportDiagnostic(configParseResult.options);
|
||||
if (isWatchSet(configParseResult.options)) {
|
||||
reportWatchModeWithoutSysSupport();
|
||||
createWatchOfConfigFile(configParseResult, commandLineOptions);
|
||||
@@ -117,7 +117,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
udpateReportDiagnostic(commandLineOptions);
|
||||
updateReportDiagnostic(commandLineOptions);
|
||||
if (isWatchSet(commandLineOptions)) {
|
||||
reportWatchModeWithoutSysSupport();
|
||||
createWatchOfFilesAndCompilerOptions(commandLine.fileNames, commandLineOptions);
|
||||
|
||||
@@ -2527,7 +2527,7 @@ namespace ts {
|
||||
/**
|
||||
* If two source files are for the same version of the same package, one will redirect to the other.
|
||||
* (See `createRedirectSourceFile` in program.ts.)
|
||||
* The redirect will have this set. The other will not have anything set, but see Program#sourceFileIsRedirectedTo.
|
||||
* The redirect will have this set. The redirected-to source file will be in `redirectTargetsSet`.
|
||||
*/
|
||||
/* @internal */ redirectInfo?: RedirectInfo | undefined;
|
||||
|
||||
|
||||
@@ -4271,7 +4271,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function isParameterPropertyDeclaration(node: Node): boolean {
|
||||
export function isParameterPropertyDeclaration(node: Node): node is ParameterDeclaration {
|
||||
return hasModifier(node, ModifierFlags.ParameterPropertyModifier) && node.parent.kind === SyntaxKind.Constructor && isClassLike(node.parent.parent);
|
||||
}
|
||||
|
||||
@@ -4630,11 +4630,21 @@ namespace ts {
|
||||
* parameters by name and binding patterns do not have a name.
|
||||
*/
|
||||
export function getJSDocParameterTags(param: ParameterDeclaration): ReadonlyArray<JSDocParameterTag> {
|
||||
if (param.name && isIdentifier(param.name)) {
|
||||
const name = param.name.escapedText;
|
||||
return getJSDocTags(param.parent).filter((tag): tag is JSDocParameterTag => isJSDocParameterTag(tag) && isIdentifier(tag.name) && tag.name.escapedText === name);
|
||||
if (param.name) {
|
||||
if (isIdentifier(param.name)) {
|
||||
const name = param.name.escapedText;
|
||||
return getJSDocTags(param.parent).filter((tag): tag is JSDocParameterTag => isJSDocParameterTag(tag) && isIdentifier(tag.name) && tag.name.escapedText === name);
|
||||
}
|
||||
else {
|
||||
const i = param.parent.parameters.indexOf(param);
|
||||
Debug.assert(i > -1, "Parameters should always be in their parents' parameter list");
|
||||
const paramTags = getJSDocTags(param.parent).filter(isJSDocParameterTag);
|
||||
if (i < paramTags.length) {
|
||||
return [paramTags[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
// a binding pattern doesn't have a name, so it's not possible to match it a JSDoc parameter, which is identified by name
|
||||
// return empty array for: out-of-order binding patterns and JSDoc function syntax, which has un-named parameters
|
||||
return emptyArray;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user