-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Describe the bug
Hello, I'm working on some legacy project that is using ng-annotate package.
I have a problem resulting from swc compilation, namely in the case of class definitions (and perhaps also in other situations that I have not encountered), the order of the JSDoc comment is shifted by placing the helper definition or helper import.
And this makes ng-annotate unable to process this structure. Furthermore, I suspect this state of affairs can also generate other problems, such as incorrect typing using JSDoc.
Is there any way to fix this bug, or force SWC to place these imports at the very top of the files rather than directly above the classes?
Input code
/** @ngInject */
class TestClass {
constructor (private testField) {}
}Config
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true
},
"target": "es2015",
"loose": false,
"minify": {
"compress": false,
"mangle": false
},
"transform": {
"decoratorVersion": "2022-03"
},
"preserveAllComments": true,
"externalHelpers": true
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}Link to the code that reproduces this issue
Expected behavior
SWC should compile to:
import { _ as _define_property } from "@swc/helpers/_/_define_property";
/** @ngInject */
class TestClass {
constructor(testField){
_define_property(this, "testField", void 0);
this.testField = testField;
}
}Actual behavior
SWC returns:
/* @ngInject */ import { _ as _define_property } from "@swc/helpers/_/_define_property";
class TestClass {
constructor(testField){
_define_property(this, "testField", void 0);
this.testField = testField;
}
}Version
1.13.20
Additional context
For anyone looking for workaround - I found out that preprocessing all JS/TS files to add semicolon (;) at the beginning of a file tricks compiler to work correctly.