optimization: Dead Code issue
During my testing, I found we have some dead code in the project and can we have a discuss how can we handle it properly?
I will give an example here:
File: src/parser.ts
Function: parseNamespace
DeadCode Block:
if (tn.skipIdentifier()) {
///...
} else {
this.error(
DiagnosticCode.Identifier_expected,
tn.range()
);
}
actually, the program already have the identifier check before:
located at: parser.parseTopLevelStatement(), with this block
case Token.NAMESPACE: {
let state = tn.mark();
tn.next();
if (tn.peek(false, IdentifierHandling.PREFER) == Token.IDENTIFIER) {
tn.discard(state);
statement = this.parseNamespace(tn, flags, decorators, startPos);
decorators = null;
} else {
tn.reset(state);
statement = this.parseStatement(tn, true);
}
break;
}
so, what should be the suggestion for this kind of situation?
should we remove the duplicated check from function parseNamespace?
Looks like, if parseNamespace is only used within parseTopLevelStatement, the code could be changed to obtain the identifier already in parseTopLevelStatement, passing it down to parseNamespace as an additional argument, in turn removing the unnecessary branch, any duplicate work (checking then reading) and perhaps even the need for a resettable state.
@dcodeIO I created a draft PR, please kindly review, thank you.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!