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

Individually track unsafe getters #29

Merged
merged 1 commit into from
Nov 2, 2020
Merged

Individually track unsafe getters #29

merged 1 commit into from
Nov 2, 2020

Conversation

guybedford
Copy link
Collaborator

This updates the getter parsing to specifically track unsafe getters to ensure they are never emitted.

This happens for example in pg with:

 Object.defineProperty(module.exports, 'native', {
    configurable: true,
    enumerable: false,
    get() {
      var native = null
      try {
        native = new PG(require('./native'))
      } catch (err) {
        if (err.code !== 'MODULE_NOT_FOUND') {
          throw err
        }
        /* eslint-disable no-console */
        console.error(err.message)
        /* eslint-enable no-console */
      }

      // overwrite module.exports.native so that getter is never called again
      Object.defineProperty(module.exports, 'native', {
        value: native,
      })

      return native
    },
  })

where the internal defineProperty with a value definition to do the replacement after the getter has been called is seen as a safe getter so the export is emitted.

Instead we define an unsafe getter to mean any getter definition which does not fit one of the safe determined patterns. Once there is an unsafe definition for a given export name, it will never be emitted as an export even if there is a subsequent safe emission pattern.

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.

1 participant