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(findExports): correctly dedup named exports #86
Changes from 2 commits
7a597b7
ecfef01
f00194f
e926e49
fbf5c41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,15 +135,14 @@ export function findExports (code: string): ESMExport[] { | |
return [] | ||
} | ||
|
||
return exports.filter((exp, index, exports) => { | ||
return exports | ||
// Filter false positive export matches | ||
if (exportLocations && !_isExportStatement(exportLocations, exp)) { | ||
return false | ||
} | ||
.filter(exp => !exportLocations || _isExportStatement(exportLocations, exp)) | ||
// Prevent multiple exports of same function, only keep latest iteration of signatures | ||
const nextExport = exports[index + 1] | ||
return !nextExport || exp.type !== nextExport.type || !exp.name || exp.name !== nextExport.name | ||
}) | ||
.filter((exp, index, exports) => { | ||
const nextExport = exports[index + 1] | ||
return !nextExport || exp.type !== nextExport.type || !exp.name || exp.name !== nextExport.name | ||
}) | ||
} | ||
|
||
export function findExportNames (code: string): string[] { | ||
|
@@ -179,7 +178,10 @@ interface TokenLocation { | |
} | ||
|
||
function _isExportStatement (exportsLocation: TokenLocation[], exp: ESMExport) { | ||
return exportsLocation.some(location => exp.start <= location.start && exp.end >= location.end) | ||
return exportsLocation.some(location => | ||
(exp.start <= location.start && location.start <= exp.end) || | ||
(exp.start <= location.end && location.end <= exp.end) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previous condition (token within match) seems keep tests pass. Why we need to change it to (token start within match || token end within match)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Made it into a comment to marge fix asap. fbf5c41. Would be happy to discuss more and change checking strategy if you think there is a case needs this check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my initial assumption of the cause - yes I think we don't need to change it for this case. |
||
) | ||
} | ||
|
||
function _tryGetExportLocations (code: string) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We were dedupe with the one that filtered out by AST. Changed to two passes of
.filter
to ensureexports
is the real exports we want for dedupe.