-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript compiler is removing some important comments. #13381
Comments
It seems that this behavior cannot be easily disabled: Plugin writing possibilities seem to be rather limited:
Possibly related: |
Solution that works is changing the order of Some caveats:
Output generated by Webpack
TS input file content// ✅ comment followed by an used import
import usedFunc from './usedfunc';
// ❌ comment followed by an unused import
import unusedFunc from './unusedfunc';
// ❌ comment followed by a type import
import type { Type } from './type';
// @if CK_DEBUG // console.warn( '✅' );
/**
*
*/
class A {
// @if CK_DEBUG // value1 = '✅';
constructor() {
}
// @if CK_DEBUG // value2 = '✅';
/**
* doc
*/
public method(): void {
// @if CK_DEBUG // console.warn( '✅' );
while ( true ) {
usedFunc();
// @if CK_DEBUG // console.warn( '✅' );
}
}
// @if CK_DEBUG // value3 = '❌';
}
// @if CK_DEBUG // console.warn( '❌' );
/**
*
*/
interface B {
/**
* doc
*/
readonly x: string;
// @if CK_DEBUG // readonly y: '❌';
}
// @if CK_DEBUG // console.warn( '✅' );
export { A };
// @if CK_DEBUG // console.warn( '❌' );
export type { A as A2 };
// @if CK_DEBUG // console.warn( '✅' );
const foo = new A();
console.log( foo ); Webpack output currently:this is invalid JS // ✅ comment followed by an used import
/* @if CK_DEBUG */ console.warn( '✅' );
/**
*
*/
class A {
/* @if CK_DEBUG */ value1 = '✅';
constructor() {
}
/* @if CK_DEBUG */ value2 = '✅';
/**
* doc
*/
method() {
/* @if CK_DEBUG */ console.warn( '✅' );
while (true) {
(0,_usedfunc__WEBPACK_IMPORTED_MODULE_0__["default"])();
/* @if CK_DEBUG */ console.warn( '✅' );
}
}
}
/* @if CK_DEBUG */ console.warn( '✅' );
/* @if CK_DEBUG */ console.warn( '✅' );
const foo = new A();
console.log(foo); Webpack output after switching loader order:this is valid JS // ✅ comment followed by an used import
/* @if CK_DEBUG */ console.warn('✅');
/**
*
*/
class A {
constructor() {
/* @if CK_DEBUG */ this.value1 = '✅';
/* @if CK_DEBUG */ this.value2 = '✅';
/* @if CK_DEBUG */ this.value3 = '❌';
}
/**
* doc
*/
method() {
/* @if CK_DEBUG */ console.warn('✅');
while (true) {
(0,_usedfunc__WEBPACK_IMPORTED_MODULE_0__["default"])();
/* @if CK_DEBUG */ console.warn('✅');
}
}
}
/* @if CK_DEBUG */ console.warn('❌');
/* @if CK_DEBUG */ console.warn('✅');
/* @if CK_DEBUG */ console.warn('❌');
/* @if CK_DEBUG */ console.warn('✅');
const foo = new A();
console.log(foo); |
Sounds good. Make sure to update both test environments: automated and manual. |
PRs: (they have to be used together, either one without the other will not work)
Despite there being |
@mremiszewski Were you you dealing with a specific case when describing this issue? If so, could you please check whether those PRs fix the issue? |
Fix (tests): Swapped an order of loaders when processing the TypeScript files. The `ck-debug-loader` is executed before `ts-loader` to avoid the removal of `CK_DEBUG_*` comments from the source code. See ckeditor/ckeditor5#13381. MAJOR BREAKING CHANGE (tests): The code specified in the `CK_DEBUG_*` flags must be valid TypeScript code as it is processed before `ts-loader`.
Fixed the TypeScript code hidden behind the `CK_DEBUG_*` flags. Closes #13381.
📝 Provide detailed reproduction steps (if any)
Some code in
*.ts
files that is marked withCK_DEBUG
is being removed by Typescript compiler because it's treated as a comment.✔️ Expected result
No lines with
CK_DEBUG
are being removed during compilation.❌ Actual result
Some lines with
CK_DEBUG
are being removed during compilation.❓ Possible solution
Workaround:
Comments with ❌ would be deleted during compilation, and comments with ✅ would be preserved.
All lines in
*.ts
files withCK_DEBUG
orCK_DEBUG_<something>
should be investigated whether they are being removed during compilation and moved to a place where they wouldn't.The same should be done for
*.js
files as the same issue will affect them when they are rewritten to Typescript.Actual solution:
We should think about a different approach to code that should be available only in debug mode.
📃 Other details
If you'd like to see this fixed sooner, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: