Skip to content

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.

@guybedford guybedford merged commit d38263b into master Nov 2, 2020
@guybedford guybedford deleted the unsafe-getters branch November 2, 2020 16:04
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