Merge pull request #3063 from Microsoft/removeDefineFunctionName
Removed Object.defineProperty for function name
This commit is contained in:
commit
93e2f91398
30
bin/tsc.js
30
bin/tsc.js
|
@ -13005,16 +13005,31 @@ var ts;
|
|||
return type;
|
||||
}
|
||||
var prototypeProperty = getPropertyOfType(rightType, "prototype");
|
||||
if (!prototypeProperty) {
|
||||
return type;
|
||||
}
|
||||
if (prototypeProperty) {
|
||||
var targetType = getTypeOfSymbol(prototypeProperty);
|
||||
if (targetType !== anyType) {
|
||||
if (isTypeSubtypeOf(targetType, type)) {
|
||||
return targetType;
|
||||
}
|
||||
if (type.flags & 16384) {
|
||||
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
|
||||
}
|
||||
}
|
||||
}
|
||||
var constructSignatures;
|
||||
if (rightType.flags & 2048) {
|
||||
constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
|
||||
}
|
||||
else if (rightType.flags & 32768) {
|
||||
constructSignatures = getSignaturesOfType(rightType, 1);
|
||||
}
|
||||
if (constructSignatures && constructSignatures.length !== 0) {
|
||||
var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
|
||||
if (type.flags & 16384) {
|
||||
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); }));
|
||||
}
|
||||
return instanceType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
function narrowType(type, expr, assumeTrue) {
|
||||
|
@ -23260,15 +23275,6 @@ var ts;
|
|||
scopeEmitEnd();
|
||||
if (thisNodeIsDecorated) {
|
||||
write(";");
|
||||
if (node.name) {
|
||||
writeLine();
|
||||
write("Object.defineProperty(");
|
||||
emitDeclarationName(node);
|
||||
write(", \"name\", { value: \"");
|
||||
emitDeclarationName(node);
|
||||
write("\", configurable: true });");
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
if (isClassExpressionWithStaticProperties) {
|
||||
for (var _a = 0; _a < staticProperties.length; _a++) {
|
||||
|
|
|
@ -13389,16 +13389,31 @@ var ts;
|
|||
return type;
|
||||
}
|
||||
var prototypeProperty = getPropertyOfType(rightType, "prototype");
|
||||
if (!prototypeProperty) {
|
||||
return type;
|
||||
}
|
||||
if (prototypeProperty) {
|
||||
var targetType = getTypeOfSymbol(prototypeProperty);
|
||||
if (targetType !== anyType) {
|
||||
if (isTypeSubtypeOf(targetType, type)) {
|
||||
return targetType;
|
||||
}
|
||||
if (type.flags & 16384) {
|
||||
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
|
||||
}
|
||||
}
|
||||
}
|
||||
var constructSignatures;
|
||||
if (rightType.flags & 2048) {
|
||||
constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
|
||||
}
|
||||
else if (rightType.flags & 32768) {
|
||||
constructSignatures = getSignaturesOfType(rightType, 1);
|
||||
}
|
||||
if (constructSignatures && constructSignatures.length !== 0) {
|
||||
var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
|
||||
if (type.flags & 16384) {
|
||||
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); }));
|
||||
}
|
||||
return instanceType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
function narrowType(type, expr, assumeTrue) {
|
||||
|
@ -23644,15 +23659,6 @@ var ts;
|
|||
scopeEmitEnd();
|
||||
if (thisNodeIsDecorated) {
|
||||
write(";");
|
||||
if (node.name) {
|
||||
writeLine();
|
||||
write("Object.defineProperty(");
|
||||
emitDeclarationName(node);
|
||||
write(", \"name\", { value: \"");
|
||||
emitDeclarationName(node);
|
||||
write("\", configurable: true });");
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
if (isClassExpressionWithStaticProperties) {
|
||||
for (var _a = 0; _a < staticProperties.length; _a++) {
|
||||
|
|
|
@ -15732,18 +15732,35 @@ var ts;
|
|||
}
|
||||
// Target type is type of prototype property
|
||||
var prototypeProperty = getPropertyOfType(rightType, "prototype");
|
||||
if (!prototypeProperty) {
|
||||
return type;
|
||||
}
|
||||
if (prototypeProperty) {
|
||||
var targetType = getTypeOfSymbol(prototypeProperty);
|
||||
// Narrow to target type if it is a subtype of current type
|
||||
if (targetType !== anyType) {
|
||||
// Narrow to the target type if it's a subtype of the current type
|
||||
if (isTypeSubtypeOf(targetType, type)) {
|
||||
return targetType;
|
||||
}
|
||||
// If current type is a union type, remove all constituents that aren't subtypes of target type
|
||||
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
|
||||
if (type.flags & 16384 /* Union */) {
|
||||
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Target type is type of construct signature
|
||||
var constructSignatures;
|
||||
if (rightType.flags & 2048 /* Interface */) {
|
||||
constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
|
||||
}
|
||||
else if (rightType.flags & 32768 /* Anonymous */) {
|
||||
constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */);
|
||||
}
|
||||
if (constructSignatures && constructSignatures.length !== 0) {
|
||||
var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
|
||||
// Pickup type from union types
|
||||
if (type.flags & 16384 /* Union */) {
|
||||
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); }));
|
||||
}
|
||||
return instanceType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
// Narrow the given type based on the given expression having the assumed boolean value. The returned type
|
||||
|
@ -27577,6 +27594,7 @@ var ts;
|
|||
writeLine();
|
||||
emitToken(15 /* CloseBraceToken */, node.members.end);
|
||||
scopeEmitEnd();
|
||||
// TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now.
|
||||
// For a decorated class, we need to assign its name (if it has one). This is because we emit
|
||||
// the class as a class expression to avoid the double-binding of the identifier:
|
||||
//
|
||||
|
@ -27586,15 +27604,6 @@ var ts;
|
|||
//
|
||||
if (thisNodeIsDecorated) {
|
||||
write(";");
|
||||
if (node.name) {
|
||||
writeLine();
|
||||
write("Object.defineProperty(");
|
||||
emitDeclarationName(node);
|
||||
write(", \"name\", { value: \"");
|
||||
emitDeclarationName(node);
|
||||
write("\", configurable: true });");
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
// Emit static property assignment. Because classDeclaration is lexically evaluated,
|
||||
// it is safe to emit static property assignment after classDeclaration
|
||||
|
|
|
@ -15732,18 +15732,35 @@ var ts;
|
|||
}
|
||||
// Target type is type of prototype property
|
||||
var prototypeProperty = getPropertyOfType(rightType, "prototype");
|
||||
if (!prototypeProperty) {
|
||||
return type;
|
||||
}
|
||||
if (prototypeProperty) {
|
||||
var targetType = getTypeOfSymbol(prototypeProperty);
|
||||
// Narrow to target type if it is a subtype of current type
|
||||
if (targetType !== anyType) {
|
||||
// Narrow to the target type if it's a subtype of the current type
|
||||
if (isTypeSubtypeOf(targetType, type)) {
|
||||
return targetType;
|
||||
}
|
||||
// If current type is a union type, remove all constituents that aren't subtypes of target type
|
||||
// If the current type is a union type, remove all constituents that aren't subtypes of the target.
|
||||
if (type.flags & 16384 /* Union */) {
|
||||
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, targetType); }));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Target type is type of construct signature
|
||||
var constructSignatures;
|
||||
if (rightType.flags & 2048 /* Interface */) {
|
||||
constructSignatures = resolveDeclaredMembers(rightType).declaredConstructSignatures;
|
||||
}
|
||||
else if (rightType.flags & 32768 /* Anonymous */) {
|
||||
constructSignatures = getSignaturesOfType(rightType, 1 /* Construct */);
|
||||
}
|
||||
if (constructSignatures && constructSignatures.length !== 0) {
|
||||
var instanceType = getUnionType(ts.map(constructSignatures, function (signature) { return getReturnTypeOfSignature(getErasedSignature(signature)); }));
|
||||
// Pickup type from union types
|
||||
if (type.flags & 16384 /* Union */) {
|
||||
return getUnionType(ts.filter(type.types, function (t) { return isTypeSubtypeOf(t, instanceType); }));
|
||||
}
|
||||
return instanceType;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
// Narrow the given type based on the given expression having the assumed boolean value. The returned type
|
||||
|
@ -27577,6 +27594,7 @@ var ts;
|
|||
writeLine();
|
||||
emitToken(15 /* CloseBraceToken */, node.members.end);
|
||||
scopeEmitEnd();
|
||||
// TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now.
|
||||
// For a decorated class, we need to assign its name (if it has one). This is because we emit
|
||||
// the class as a class expression to avoid the double-binding of the identifier:
|
||||
//
|
||||
|
@ -27586,15 +27604,6 @@ var ts;
|
|||
//
|
||||
if (thisNodeIsDecorated) {
|
||||
write(";");
|
||||
if (node.name) {
|
||||
writeLine();
|
||||
write("Object.defineProperty(");
|
||||
emitDeclarationName(node);
|
||||
write(", \"name\", { value: \"");
|
||||
emitDeclarationName(node);
|
||||
write("\", configurable: true });");
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
// Emit static property assignment. Because classDeclaration is lexically evaluated,
|
||||
// it is safe to emit static property assignment after classDeclaration
|
||||
|
|
|
@ -3898,6 +3898,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|||
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
|
||||
scopeEmitEnd();
|
||||
|
||||
// TODO(rbuckton): Need to go back to `let _a = class C {}` approach, removing the defineProperty call for now.
|
||||
|
||||
// For a decorated class, we need to assign its name (if it has one). This is because we emit
|
||||
// the class as a class expression to avoid the double-binding of the identifier:
|
||||
//
|
||||
|
@ -3907,15 +3909,6 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|||
//
|
||||
if (thisNodeIsDecorated) {
|
||||
write(";");
|
||||
if (node.name) {
|
||||
writeLine();
|
||||
write("Object.defineProperty(");
|
||||
emitDeclarationName(node);
|
||||
write(", \"name\", { value: \"");
|
||||
emitDeclarationName(node);
|
||||
write("\", configurable: true });");
|
||||
writeLine();
|
||||
}
|
||||
}
|
||||
|
||||
// Emit static property assignment. Because classDeclaration is lexically evaluated,
|
||||
|
|
|
@ -21,7 +21,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|||
function decorate() { }
|
||||
let Decorated = class {
|
||||
};
|
||||
Object.defineProperty(Decorated, "name", { value: "Decorated", configurable: true });
|
||||
Decorated = __decorate([
|
||||
decorate
|
||||
], Decorated);
|
||||
|
|
Loading…
Reference in a new issue