mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
[Transforms] Fix emit comment in synthesized function expression (#8234)
* Do not emit leading comment of synthesized function expression in object literal property assignment * Update baselines
This commit is contained in:
@@ -1981,7 +1981,9 @@ const _super = (function (geti, seti) {
|
||||
// }
|
||||
// "comment1" is not considered to be leading comment for node.initializer
|
||||
// but rather a trailing comment on the previous node.
|
||||
emitLeadingComments(node.initializer, getTrailingComments(collapseRangeToStart(node.initializer)));
|
||||
if (!shouldSkipLeadingCommentsForNode(node.initializer)) {
|
||||
emitLeadingComments(node.initializer, getTrailingComments(collapseRangeToStart(node.initializer)));
|
||||
}
|
||||
emitExpression(node.initializer);
|
||||
}
|
||||
|
||||
|
||||
@@ -1175,13 +1175,25 @@ namespace ts {
|
||||
const propertyName = createExpressionForPropertyName(visitNode(firstAccessor.name, visitor, isPropertyName));
|
||||
propertyName.end = firstAccessor.name.end;
|
||||
|
||||
let getAccessorExpression: FunctionExpression;
|
||||
if (getAccessor) {
|
||||
getAccessorExpression = transformFunctionLikeToExpression(getAccessor, /*location*/ getAccessor, /*name*/ undefined);
|
||||
setNodeEmitFlags(getAccessorExpression, NodeEmitFlags.NoLeadingComments | getNodeEmitFlags(getAccessorExpression));
|
||||
}
|
||||
|
||||
let setAccessorExpression: FunctionExpression;
|
||||
if (setAccessor) {
|
||||
setAccessorExpression = transformFunctionLikeToExpression(setAccessor, /*location*/ setAccessor, /*name*/ undefined);
|
||||
setNodeEmitFlags(setAccessorExpression, NodeEmitFlags.NoLeadingComments | getNodeEmitFlags(setAccessorExpression));
|
||||
}
|
||||
|
||||
return setNodeEmitFlags(
|
||||
createObjectDefineProperty(
|
||||
target,
|
||||
propertyName,
|
||||
/*descriptor*/ {
|
||||
get: getAccessor && transformFunctionLikeToExpression(getAccessor, /*location*/ getAccessor, /*name*/ undefined),
|
||||
set: setAccessor && transformFunctionLikeToExpression(setAccessor, /*location*/ setAccessor, /*name*/ undefined),
|
||||
get: getAccessorExpression,
|
||||
set: setAccessorExpression,
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
},
|
||||
@@ -2283,9 +2295,11 @@ namespace ts {
|
||||
// Methods on classes are handled in visitClassDeclaration/visitClassExpression.
|
||||
// Methods with computed property names are handled in visitObjectLiteralExpression.
|
||||
Debug.assert(!isComputedPropertyName(node.name));
|
||||
const functionExpression = transformFunctionLikeToExpression(node, /*location*/ node, /*name*/ undefined);
|
||||
setNodeEmitFlags(functionExpression, NodeEmitFlags.NoLeadingComments | getNodeEmitFlags(functionExpression));
|
||||
return createPropertyAssignment(
|
||||
node.name,
|
||||
transformFunctionLikeToExpression(node, /*location*/ node, /*name*/ undefined),
|
||||
functionExpression,
|
||||
/*location*/ node
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ var b = {
|
||||
foo: function (x) {
|
||||
if (x === void 0) { x = 1; }
|
||||
},
|
||||
foo: // error
|
||||
function (x) {
|
||||
foo: function (x) {
|
||||
if (x === void 0) { x = 1; }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -103,8 +103,7 @@ var C = (function () {
|
||||
function C() {
|
||||
} // ok
|
||||
Object.defineProperty(C.prototype, "X", {
|
||||
get: // error
|
||||
function () {
|
||||
get: function () {
|
||||
return '';
|
||||
},
|
||||
set: function (v) { } // ok
|
||||
|
||||
Reference in New Issue
Block a user