mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Retain synthetic comments on classes and their properties.
This commit is contained in:
@@ -1245,6 +1245,7 @@ namespace ts {
|
||||
const statement = createExpressionStatement(transformInitializedProperty(property, receiver));
|
||||
setSourceMapRange(statement, moveRangePastModifiers(property));
|
||||
setCommentRange(statement, property);
|
||||
setOriginalNode(statement, property);
|
||||
statements.push(statement);
|
||||
}
|
||||
}
|
||||
@@ -1262,6 +1263,7 @@ namespace ts {
|
||||
startOnNewLine(expression);
|
||||
setSourceMapRange(expression, moveRangePastModifiers(property));
|
||||
setCommentRange(expression, property);
|
||||
setOriginalNode(expression, property);
|
||||
expressions.push(expression);
|
||||
}
|
||||
|
||||
|
||||
@@ -334,6 +334,29 @@ export {Value};
|
||||
}
|
||||
}).outputText;
|
||||
});
|
||||
|
||||
// https://github.com/Microsoft/TypeScript/issues/17594
|
||||
testBaseline("transformAddCommentToProperties", () => {
|
||||
return transpileModule(`
|
||||
// class comment.
|
||||
class Clazz {
|
||||
// original comment 1.
|
||||
static staticProp: number = 1;
|
||||
// original comment 2.
|
||||
instanceProp: number = 2;
|
||||
// original comment 3.
|
||||
constructor(readonly field = 1) {}
|
||||
}
|
||||
`, {
|
||||
transformers: {
|
||||
before: [addSyntheticComment(n => isPropertyDeclaration(n) || isParameterPropertyDeclaration(n) || isClassDeclaration(n) || isConstructorDeclaration(n))],
|
||||
},
|
||||
compilerOptions: {
|
||||
target: ScriptTarget.ES2015,
|
||||
newLine: NewLineKind.CarriageReturnLineFeed,
|
||||
}
|
||||
}).outputText;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class X {
|
||||
constructor() {
|
||||
// new comment!
|
||||
// original comment.
|
||||
this.foo = 1;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/*comment*/
|
||||
class Clazz {
|
||||
/*comment*/
|
||||
constructor(/*comment*/
|
||||
field = 1) {
|
||||
this.field = field;
|
||||
/*comment*/
|
||||
this.instanceProp = 2;
|
||||
}
|
||||
}
|
||||
/*comment*/
|
||||
Clazz.staticProp = 1;
|
||||
Reference in New Issue
Block a user