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

strictMode disabled causes SyntaxError with exportDefaultFrom #9858

Open
sebdeckers opened this Issue Apr 14, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@sebdeckers
Copy link
Contributor

commented Apr 14, 2019

Bug Report

Current Behavior
Fails with strictMode: false, passes with strictMode: true.

Input Code

const parser = require('@babel/parser')
const source = `
  export { f }
  function f () {}
`
const options = {
  sourceType: 'module',
  plugins: ['exportDefaultFrom']
}

parser.parse(source, { ...options, strictMode: true })
// OK

parser.parse(source, { ...options, strictMode: false })
// SyntaxError: Export 'f' is not defined (2:11)

Expected behavior/code
Disabling strict mode should not cause a syntax error for code that parses with strict mode enabled.

Babel Configuration (.babelrc, package.json, cli command)

N/A, see example code above

Environment

  • Babel version(s): v7.4.3
  • Node/npm version: Node 11.13.0/npm 6.7.0
  • OS: macOS 10.13.6 (High Sierra)
  • Monorepo: no
  • How you are using Babel: parser

Possible Solution

N/A

Additional context/Screenshots

Originally came across this problem while parsing Moment.js source code.

moment/src/lib/utils/hooks.js

https://github.com/moment/moment/blob/92c28cb639d7537d00f9f48f326e5f1ced4c869b/src/lib/utils/hooks.js

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Apr 14, 2019

Hey @sebdeckers! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo

This comment has been minimized.

Copy link
Member

commented Apr 14, 2019

Are you sure @babel/parser is 7.4.3? It should have been fixed by #9725

@sebdeckers

This comment has been minimized.

Copy link
Contributor Author

commented Apr 15, 2019

@nicolo-ribaudo I can confirm that it is 7.4.3 and that patch is included.

package-lock.json

{
  "name": "test-babel-parser",
  "version": "1.0.0",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "@babel/parser": {
      "version": "7.4.3",
      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.4.3.tgz",
      "integrity": "sha512-gxpEUhTS1sGA63EGQGuA+WESPR/6tz6ng7tSHFCmaTJK/cGK8y37cBTspX+U2xCAue2IQVvF6Z0oigmjwD8YGQ=="
    }
  }
}

node_modules/@babel/parser/lib/index.js

  checkLocalExport(id) {
    if (this.scopeStack[0].lexical.indexOf(id.name) === -1 && this.scopeStack[0].var.indexOf(id.name) === -1 && this.scopeStack[0].functions.indexOf(id.name) === -1) {
      this.undefinedExports.set(id.name, id.start);
    }
  }
@sebdeckers

This comment has been minimized.

Copy link
Contributor Author

commented Apr 15, 2019

@nicolo-ribaudo nicolo-ribaudo referenced a pull request that will close this issue Apr 16, 2019

Open

Always register global bindings as exportable #9865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.