Martin Probst faee7b3621
Avoid printing comments on static fields twice. (#47363)
* Avoid printing comments on static fields twice.

In TS4.4, when a transformer adds a static field with a synthetic
comment to a decorated class, TS prints the synthetic comment twice:

  @Decorator
  class MyClass {
    /* comment */ staticField = 'x';  // field and comment added by transformer
  }

Becomes:

  var MyClass = class MyClass {}
  /*comment*/
  /*comment*/
  MyClass.newField = "x";
  __decorate(MyClass, Decorator, ...)

This is because the classFields transformer calls `setOriginalNode(n,
propertyDeclaration)` on both the expression statement , and the
assignment expression contained in it, leading to the synthetic comment
appearing twice.

This change avoids the problem by explicitly deleting any synthetic
comments from the assignment expression created for static fields when
creating the expression statement containing the assignment. This allows
us to retain the information of the original node without printing the
synthetic comment twice.

* Update src/testRunner/unittests/transform.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2022-01-11 12:19:36 -08:00
..