-
Notifications
You must be signed in to change notification settings - Fork 710
Description
While using legal comments to preserve placeholders for later processing by JS plugins, I noticed that some legal comments gets removed based on the state of the proceeding statement, if the statement is preserved then it gets preserved otherwise it gets removed which breaks the block marking use-case.
Example
For example eliminating code blocks based on flags passed during build, or for start-marker/end-marker use-cases:
function doStuff() {
/*! dev-only-start */
if (someCondition) {
doSomething();
}
/*! dev-only-end */
const clientOptions = {
enabled: true
};
return wrap(clientOptions);
}
export { doStuff }Output
//#region main.ts
function doStuff() {
/*! dev-only-start */
if (someCondition) doSomething();
// ⚠️ Missing end marker here
return wrap({ enabled: true });
}
//#endregion
export { doStuff };Ideally the legal marker should be preserved regardless of the next statement status.
Workarounds
Putting the end marker right before a statement works as long as the statement itself doesn't get "optimized", in my example the clientOptions gets inlined into the wrap call, which would remove the end marker if it was above it.
Only way for this to work is to put it above the return wrap(...) call since it doesn't get removed, but this is flimsy and assumes a lot about the output that may get changed under the hood at anytime.
Reproduction
Alternatives
If this cannot be done with legal comments then we need a way to preserve certain comments, of course with exceptions regarding if their container/associated statement got tree-shaken out or not. in other words, I guess we need a way to preserve legal comments that precedes an empty line.
Or maybe introduce a block comment structure for marking regions/lines