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: RollupJS reexports detection #59

Merged
merged 2 commits into from
Jul 15, 2021
Merged

Conversation

guybedford
Copy link
Collaborator

This fixes the RollupJS reexports detection implemented in #41 due to the typo pointed out by @sodatea in https://github.com/guybedford/cjs-module-lexer/pull/41/files#r667619960.

@nicolo-ribaudo review would be very welcome if you have the time, cannot afford any mistakes here if we do a full backport.

@@ -113,7 +113,7 @@ EXPORT_STAR_LIB: `Object.keys(` IDENTIFIER$1 `).forEach(function (` IDENTIFIER$2
(`if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`)?
)?
) |
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER$1 `, ` IDENTIFIER$2 `)` | IDENTIFIER$1 `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)` | IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be like this:

Suggested change
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)` | IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`
`if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` (`Object` `.prototype`? `.hasOwnProperty.call(` EXPORTS_IDENTIFIER `, ` IDENTIFIER$2 `)` | EXPORTS_IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)`))? `)`

Copy link
Contributor

Choose a reason for hiding this comment

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

Or well, maybe not because EXPORTS_IDENTIFIER also allows module.exports. But we should expect the exact exports identifier, not a generic one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason this is generic is due to the export names object check for Babel here - https://github.com/guybedford/cjs-module-lexer/blob/master/test/_unit.js#L171.

Comment on lines +654 to +656
if (ch === 79/*O*/ && source.startsWith('bject', pos + 1) && source[pos + 6] === '.') {
if (!tryParseObjectHasOwnProperty(it_id)) break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This has just been moved here from the old else branch without changing the semantics, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the order switch is so that pos doesn't get changed for the fallback check.

@guybedford
Copy link
Collaborator Author

I'm seriously considering if this PR is even worth merging given the current state of compatibility over older Node.js versions.

There is a very real risk of package interops working for some Node.js versions and not others which seems very risky.

Does anyone have any feedback on this?

@nicolo-ribaudo
Copy link
Contributor

Isn't it already the case? Or did you backport the last cjs lexer version to every Node.js version using it?

@guybedford
Copy link
Collaborator Author

@nicolo-ribaudo up until now I've been running backports back to 12 even, since these are all backwards compatible. The issue is more just something working only on newer 12 / 14 which is the urgency to stabilize here.

@guybedford guybedford merged commit 32cfbbf into master Jul 15, 2021
@guybedford guybedford deleted the rollup-reexports-fix branch July 15, 2021 19:30
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.

2 participants