mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-16 15:44:16 -06:00
Fix emit for accessors with missing bodies
This commit is contained in:
parent
25998ae865
commit
2c03633eda
@ -2108,7 +2108,8 @@ namespace ts {
|
||||
|
||||
// A GetAccessor or SetAccessor is TypeScript syntax if it is either abstract,
|
||||
// or has both a computed property name and a decorator.
|
||||
if (hasModifier(node, ModifierFlags.Abstract)
|
||||
if ((<AccessorDeclaration>node).body === undefined
|
||||
|| hasModifier(node, ModifierFlags.Abstract)
|
||||
|| (subtreeFlags & TransformFlags.ContainsDecorators
|
||||
&& subtreeFlags & TransformFlags.ContainsComputedPropertyName)) {
|
||||
transformFlags = TransformFlags.AssertTypeScript;
|
||||
|
||||
@ -1810,18 +1810,28 @@ namespace ts {
|
||||
* @param node The get accessor node.
|
||||
*/
|
||||
function visitGetAccessor(node: GetAccessorDeclaration) {
|
||||
if (shouldElideFunctionLikeDeclaration(node)) {
|
||||
if (shouldElideAccessorDeclaration(node)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return createGetAccessor(
|
||||
visitNodes(node.modifiers, visitor, isModifier),
|
||||
visitPropertyNameOfClassElement(node),
|
||||
visitEachChild(node.body, visitor, context),
|
||||
node.body ? visitEachChild(node.body, visitor, context) : createBlock([]),
|
||||
node
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a function-like declaration should be elided. A declaration should
|
||||
* be elided if it is an overload, is abstract, or is an ambient declaration.
|
||||
*
|
||||
* @param node The declaration node.
|
||||
*/
|
||||
function shouldElideAccessorDeclaration(node: AccessorDeclaration) {
|
||||
return hasModifier(node, ModifierFlags.Abstract | ModifierFlags.Ambient);
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits a set accessor declaration of a class.
|
||||
*
|
||||
@ -1832,7 +1842,7 @@ namespace ts {
|
||||
* @param node The set accessor node.
|
||||
*/
|
||||
function visitSetAccessor(node: SetAccessorDeclaration) {
|
||||
if (shouldElideFunctionLikeDeclaration(node)) {
|
||||
if (shouldElideAccessorDeclaration(node)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@ -1840,7 +1850,7 @@ namespace ts {
|
||||
visitNodes(node.modifiers, visitor, isModifier),
|
||||
visitPropertyNameOfClassElement(node),
|
||||
visitNode(firstOrUndefined(node.parameters), visitor, isParameter),
|
||||
visitEachChild(node.body, visitor, context),
|
||||
node.body ? visitEachChild(node.body, visitor, context) : createBlock([]),
|
||||
node
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user