Skip to content
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

fix(tsc): improve regexp performance for global type removal #4260

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

blake-newman
Copy link
Member

The issue with the removal of global types was the RegExp, for certain files written like .tsbuildinfo which is a single line long contents file it would scan the whole line scanning for the characters.

By specifying m flag it causes ^ and $ to match the begin/end of each line (not only begin/end of string).

This removes the need for the check of the filename to do the replacement check.

The issue with the removal of global types was the RegExp, for
certain files written like `.tsbuildinfo` which is a single line
long contents file it would scan the whole line scanning for the
characters.

By specifying `m` flag it causes ^ and $ to match the begin/end
of each line (not only begin/end of string).

This removes the need for the check of the filename to do the
replacement check.
@@ -65,7 +58,7 @@ export function run() {
}
}

const removeEmitGlobalTypesRegexp = /[^\n]*__VLS_globalTypesStart[\w\W]*__VLS_globalTypesEnd[^\n]*\n/g;
const removeEmitGlobalTypesRegexp = /^[^\n]*__VLS_globalTypesStart[\w\W]*__VLS_globalTypesEnd[^\n]*\n?$/mg;
Copy link
Collaborator

@rchl rchl Apr 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those initial/trailing \n make no sense with m flag. Those should be ignored anyway when matching with m flag.

Suggested change
const removeEmitGlobalTypesRegexp = /^[^\n]*__VLS_globalTypesStart[\w\W]*__VLS_globalTypesEnd[^\n]*\n?$/mg;
const removeEmitGlobalTypesRegexp = /^.*__VLS_globalTypesStart[\w\W]*__VLS_globalTypesEnd.*$/mg;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants