Retain synthetic comments on classes and their properties.

This commit is contained in:
Martin Probst
2018-07-18 17:23:27 +02:00
parent 1bd79af760
commit 2529b864f4
4 changed files with 44 additions and 0 deletions
+2
View File
@@ -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);
}
+23
View File
@@ -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;
});
});
}
@@ -0,0 +1,7 @@
class X {
constructor() {
// new comment!
// original comment.
this.foo = 1;
}
}
@@ -0,0 +1,12 @@
/*comment*/
class Clazz {
/*comment*/
constructor(/*comment*/
field = 1) {
this.field = field;
/*comment*/
this.instanceProp = 2;
}
}
/*comment*/
Clazz.staticProp = 1;