Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Microsoft/TypeScript into nojvek-…
Browse files Browse the repository at this point in the history
…jsx-fragment-factory
  • Loading branch information
nojvek committed May 28, 2020
2 parents 6eaa05b + 3bb84ef commit 4eaec97
Show file tree
Hide file tree
Showing 384 changed files with 3,775 additions and 2,715 deletions.
56 changes: 41 additions & 15 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2303,7 +2303,7 @@ namespace ts {
else {
Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
if (compilerOptions.preserveConstEnums) {
diagnosticMessage = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationName);
diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
}
}

Expand Down Expand Up @@ -4155,12 +4155,16 @@ namespace ts {
let leftStr = symbolValueDeclarationIsContextSensitive(left.symbol) ? typeToString(left, left.symbol.valueDeclaration) : typeToString(left);
let rightStr = symbolValueDeclarationIsContextSensitive(right.symbol) ? typeToString(right, right.symbol.valueDeclaration) : typeToString(right);
if (leftStr === rightStr) {
leftStr = typeToString(left, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
rightStr = typeToString(right, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
leftStr = getTypeNameForErrorDisplay(left);
rightStr = getTypeNameForErrorDisplay(right);
}
return [leftStr, rightStr];
}

function getTypeNameForErrorDisplay(type: Type) {
return typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.UseFullyQualifiedType);
}

function symbolValueDeclarationIsContextSensitive(symbol: Symbol): boolean {
return symbol && symbol.valueDeclaration && isExpression(symbol.valueDeclaration) && !isContextSensitive(symbol.valueDeclaration);
}
Expand Down Expand Up @@ -15742,23 +15746,30 @@ namespace ts {
function reportRelationError(message: DiagnosticMessage | undefined, source: Type, target: Type) {
if (incompatibleStack.length) reportIncompatibleStack();
const [sourceType, targetType] = getTypeNamesForErrorDisplay(source, target);
let generalizedSource = source;
let generalizedSourceType = sourceType;

if (isLiteralType(source) && !typeCouldHaveTopLevelSingletonTypes(target)) {
generalizedSource = getBaseTypeOfLiteralType(source);
generalizedSourceType = getTypeNameForErrorDisplay(generalizedSource);
}

if (target.flags & TypeFlags.TypeParameter) {
const constraint = getBaseConstraintOfType(target);
const constraintElab = constraint && isTypeAssignableTo(source, constraint);
if (constraintElab) {
let needsOriginalSource;
if (constraint && (isTypeAssignableTo(generalizedSource, constraint) || (needsOriginalSource = isTypeAssignableTo(source, constraint)))) {
reportError(
Diagnostics._0_is_assignable_to_the_constraint_of_type_1_but_1_could_be_instantiated_with_a_different_subtype_of_constraint_2,
sourceType,
needsOriginalSource ? sourceType : generalizedSourceType,
targetType,
typeToString(constraint!),
typeToString(constraint),
);
}
else {
reportError(
Diagnostics._0_could_be_instantiated_with_an_arbitrary_type_which_could_be_unrelated_to_1,
targetType,
sourceType
generalizedSourceType
);
}
}
Expand All @@ -15775,7 +15786,7 @@ namespace ts {
}
}

reportError(message, sourceType, targetType);
reportError(message, generalizedSourceType, targetType);
}

function tryElaborateErrorsForPrimitivesAndObjects(source: Type, target: Type) {
Expand Down Expand Up @@ -17304,9 +17315,10 @@ namespace ts {
return Ternary.True;
}
if (isGenericMappedType(source)) {
// A generic mapped type { [P in K]: T } is related to an index signature { [x: string]: U }
// if T is related to U.
return kind === IndexKind.String ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
// A generic mapped type { [P in K]: T } is related to a type with an index signature
// { [x: string]: U }, and optionally with an index signature { [x: number]: V },
// if T is related to U and V.
return getIndexTypeOfType(target, IndexKind.String) ? isRelatedTo(getTemplateTypeFromMappedType(source), targetType, reportErrors) : Ternary.False;
}
const indexType = getIndexTypeOfType(source, kind) || kind === IndexKind.Number && getIndexTypeOfType(source, IndexKind.String);
if (indexType) {
Expand Down Expand Up @@ -17372,6 +17384,21 @@ namespace ts {
}
}

function typeCouldHaveTopLevelSingletonTypes(type: Type): boolean {
if (type.flags & TypeFlags.UnionOrIntersection) {
return !!forEach((type as IntersectionType).types, typeCouldHaveTopLevelSingletonTypes);
}

if (type.flags & TypeFlags.Instantiable) {
const constraint = getConstraintOfType(type);
if (constraint) {
return typeCouldHaveTopLevelSingletonTypes(constraint);
}
}

return isUnitType(type);
}

function getBestMatchingType(source: Type, target: UnionOrIntersectionType, isRelatedTo = compareTypesAssignable) {
return findMatchingDiscriminantType(source, target, isRelatedTo, /*skipPartial*/ true) ||
findMatchingTypeReferenceOrTypeAliasReference(source, target) ||
Expand Down Expand Up @@ -33850,8 +33877,7 @@ namespace ts {
const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor;
if (basePropertyFlags && derivedPropertyFlags) {
// property/accessor is overridden with property/accessor
if (!compilerOptions.useDefineForClassFields
|| baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
if (baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
|| base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration
|| derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) {
// when the base property is abstract or from an interface, base/derived flags don't need to match
Expand All @@ -33867,7 +33893,7 @@ namespace ts {
Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor;
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType), typeToString(type));
}
else {
else if (compilerOptions.useDefineForClassFields) {
const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer);
if (uninitialized
&& !(derived.flags & SymbolFlags.Transient)
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5705,6 +5705,10 @@
"category": "Message",
"code": 95118
},
"Generate 'get' and 'set' accessors for all overriding properties": {
"category": "Message",
"code": 95119
},

"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
"category": "Error",
Expand Down
37 changes: 24 additions & 13 deletions src/compiler/transformers/module/esnextAnd2015.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,36 @@ namespace ts {
}

if (isExternalModule(node) || compilerOptions.isolatedModules) {
const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(node, compilerOptions);
if (externalHelpersImportDeclaration) {
const statements: Statement[] = [];
const statementOffset = addPrologue(statements, node.statements);
append(statements, externalHelpersImportDeclaration);

addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
return updateSourceFileNode(
node,
setTextRange(createNodeArray(statements), node.statements));
}
else {
return visitEachChild(node, visitor, context);
const result = updateExternalModule(node);
if (!isExternalModule(node) || some(result.statements, isExternalModuleIndicator)) {
return result;
}
return updateSourceFileNode(
result,
setTextRange(createNodeArray([...result.statements, createEmptyExports()]), result.statements),
);
}

return node;
}

function updateExternalModule(node: SourceFile) {
const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded(node, compilerOptions);
if (externalHelpersImportDeclaration) {
const statements: Statement[] = [];
const statementOffset = addPrologue(statements, node.statements);
append(statements, externalHelpersImportDeclaration);

addRange(statements, visitNodes(node.statements, visitor, isStatement, statementOffset));
return updateSourceFileNode(
node,
setTextRange(createNodeArray(statements), node.statements));
}
else {
return visitEachChild(node, visitor, context);
}
}

function visitor(node: Node): VisitResult<Node> {
switch (node.kind) {
case SyntaxKind.ImportEqualsDeclaration:
Expand Down
12 changes: 4 additions & 8 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ namespace ts {
IsNamedExternalExport = 1 << 4,
IsDefaultExternalExport = 1 << 5,
IsDerivedClass = 1 << 6,
UseImmediatelyInvokedFunctionExpression = 1 << 7,

HasAnyDecorators = HasConstructorDecorators | HasMemberDecorators,
NeedsName = HasStaticInitializedProperties | HasMemberDecorators,
UseImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
MayNeedImmediatelyInvokedFunctionExpression = HasAnyDecorators | HasStaticInitializedProperties,
IsExported = IsExportOfNamespace | IsDefaultExternalExport | IsNamedExternalExport,
}

Expand Down Expand Up @@ -595,6 +596,7 @@ namespace ts {
if (isExportOfNamespace(node)) facts |= ClassFacts.IsExportOfNamespace;
else if (isDefaultExternalModuleExport(node)) facts |= ClassFacts.IsDefaultExternalExport;
else if (isNamedExternalModuleExport(node)) facts |= ClassFacts.IsNamedExternalExport;
if (languageVersion <= ScriptTarget.ES5 && (facts & ClassFacts.MayNeedImmediatelyInvokedFunctionExpression)) facts |= ClassFacts.UseImmediatelyInvokedFunctionExpression;
return facts;
}

Expand Down Expand Up @@ -665,12 +667,6 @@ namespace ts {
const iife = createImmediatelyInvokedArrowFunction(statements);
setEmitFlags(iife, EmitFlags.TypeScriptClassWrapper);

// Class comment is already added by the ES2015 transform when targeting ES5 or below.
// Only add if targetting ES2015+ to prevent duplicates
if (languageVersion > ScriptTarget.ES5) {
addSyntheticLeadingComment(iife, SyntaxKind.MultiLineCommentTrivia, "* @class ");
}

const varStatement = createVariableStatement(
/*modifiers*/ undefined,
createVariableDeclarationList([
Expand All @@ -679,7 +675,7 @@ namespace ts {
/*type*/ undefined,
iife
)
], languageVersion > ScriptTarget.ES5 ? NodeFlags.Let : undefined)
])
);

setOriginalNode(varStatement, node);
Expand Down
28 changes: 14 additions & 14 deletions src/lib/es2015.core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,48 +434,48 @@ interface String {
startsWith(searchString: string, position?: number): boolean;

/**
* Returns an <a> HTML anchor element and sets the name attribute to the text value
* Returns an `<a>` HTML anchor element and sets the name attribute to the text value
* @param name
*/
anchor(name: string): string;

/** Returns a <big> HTML element */
/** Returns a `<big>` HTML element */
big(): string;

/** Returns a <blink> HTML element */
/** Returns a `<blink>` HTML element */
blink(): string;

/** Returns a <b> HTML element */
/** Returns a `<b>` HTML element */
bold(): string;

/** Returns a <tt> HTML element */
/** Returns a `<tt>` HTML element */
fixed(): string;

/** Returns a <font> HTML element and sets the color attribute value */
/** Returns a `<font>` HTML element and sets the color attribute value */
fontcolor(color: string): string;

/** Returns a <font> HTML element and sets the size attribute value */
/** Returns a `<font>` HTML element and sets the size attribute value */
fontsize(size: number): string;

/** Returns a <font> HTML element and sets the size attribute value */
/** Returns a `<font>` HTML element and sets the size attribute value */
fontsize(size: string): string;

/** Returns an <i> HTML element */
/** Returns an `<i>` HTML element */
italics(): string;

/** Returns an <a> HTML element and sets the href attribute value */
/** Returns an `<a>` HTML element and sets the href attribute value */
link(url: string): string;

/** Returns a <small> HTML element */
/** Returns a `<small>` HTML element */
small(): string;

/** Returns a <strike> HTML element */
/** Returns a `<strike>` HTML element */
strike(): string;

/** Returns a <sub> HTML element */
/** Returns a `<sub>` HTML element */
sub(): string;

/** Returns a <sup> HTML element */
/** Returns a `<sup>` HTML element */
sup(): string;
}

Expand Down

0 comments on commit 4eaec97

Please sign in to comment.