Skip to content

feat(commonjs): export properties defined using Object.defineProperty(exports, ..) #222

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

Merged
merged 3 commits into from
Feb 29, 2020

Conversation

edeustace
Copy link
Contributor

@edeustace edeustace commented Feb 21, 2020

Rollup Plugin Name: commonjs

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

This pr adds exports that have been defined using the Object.defineProperty(exports, ...) technique. I was running into an issue with a 3rd party lib (@material-ui/[email protected]) where it was using this technique to define the exports. Rollup was falling over with the error export 'foo' is not exported by 'path/to/module'.

@edeustace edeustace changed the title feat: export properties defined using Object.defineProperty(exports, ..) feat(commonjs): export properties defined using Object.defineProperty(exports, ..) Feb 21, 2020
Copy link
Collaborator

@shellscape shellscape left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for taking the time to put this together, we really appreciate it!

@lukastaegert @NotWoods please have a look

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

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

Looks good to me too, just a minor naming suggestion.

@@ -299,6 +318,10 @@ export function transformCommonjs(
return;
}

// Is this a call to Object.defineProperty(exports, ...)?
const def = defineProperty(node, 'exports');
Copy link
Member

Choose a reason for hiding this comment

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

I would rename the function to isDefinePropertyCall. Then the comment is also not needed. The return value could be propertyName, then I do not have to check the function definition what it means.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done @lukastaegert 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually on reflection I propose it be called getDefinePropertyCallName, the java programmer in me is complaining that an isX function should only return a boolean. See latest commit. That said - happy to rollback if you prefer isDefinePropertyCall.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not return a boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but we’d also need to get the property name to add to namedExports?

Copy link
Member

Choose a reason for hiding this comment

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

You are right, and you definitely got what I meant 😉

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks good. :shipit:

@shellscape shellscape merged commit a66c8c7 into rollup:master Feb 29, 2020
@shellscape
Copy link
Collaborator

thanks!

LarsDenBakker pushed a commit to LarsDenBakker/plugins that referenced this pull request Sep 12, 2020
…(exports, ..) (rollup#222)

* feat: support Object.defineProperty(exports, ..)

* chore: rename defineProperty -> isDefinePropertyCall

* chore: rename isDefinePropertyCall -> getDefinePropertyCallName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants