Add rewriteRelativeImportExtension helper by andrewbranch · Pull Request #270 · microsoft/tslib (original) (raw)

Choose a reason for hiding this comment

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

| return tsx ? preserveJsx ? ".jsx" : ".js" : d && (ext && !cm || !ext) ? m : ((d | | "") + (ext | | "") + "." + (cm | | "").toLowerCase() + "js"); | | -------------------------------------------------------------------------------------- | ----------------- | ---------------------------- | ---------------------------- | | return tsx ? preserveJsx ? ".jsx" : ".js" : d && !(ext && cm) ? m : ((d || "") + (ext | | "") + "." + (cm | | "").toLowerCase() + "js"); | |

To reduce the amount of || "" that you're doing, you could move the quantifiers inside of the capture groups so that they capture empty strings instead of undefined:

/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i

Also, to clarify the d && (ext && !cm || !ext) case: is this saying that d.ts (no ext and no cm) remains .d.ts, .d.cts (no ext but has cm) remains .d.cts, but .d.css.cts (has ext and cm) becomes .d.css.cjs?