Skip to content

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

Merged
shellscape merged 3 commits into
rollup:masterfrom
ahum:fix/failed-export
Feb 29, 2020
Merged

feat(commonjs): export properties defined using Object.defineProperty(exports, ..)#222
shellscape merged 3 commits into
rollup:masterfrom
ahum:fix/failed-export

Conversation

@edeustace

@edeustace edeustace commented Feb 21, 2020

Copy link
Copy Markdown
Contributor

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/core@3.9.4) 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

@shellscape shellscape left a comment

Copy link
Copy Markdown
Collaborator

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

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

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.

Comment thread packages/commonjs/src/transform.js Outdated
}

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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