{"action":"created","issue":{"url":"https://api.github.com/repos/babel/babel/issues/7501","repository_url":"https://api.github.com/repos/babel/babel","labels_url":"https://api.github.com/repos/babel/babel/issues/7501/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel/issues/7501/comments","events_url":"https://api.github.com/repos/babel/babel/issues/7501/events","html_url":"https://github.com/babel/babel/pull/7501","id":302502494,"number":7501,"title":"Default to sourceType:script when parsing files.","user":{"login":"loganfsmyth","id":132260,"avatar_url":"https://avatars1.githubusercontent.com/u/132260?v=4","gravatar_id":"","url":"https://api.github.com/users/loganfsmyth","html_url":"https://github.com/loganfsmyth","followers_url":"https://api.github.com/users/loganfsmyth/followers","following_url":"https://api.github.com/users/loganfsmyth/following{/other_user}","gists_url":"https://api.github.com/users/loganfsmyth/gists{/gist_id}","starred_url":"https://api.github.com/users/loganfsmyth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loganfsmyth/subscriptions","organizations_url":"https://api.github.com/users/loganfsmyth/orgs","repos_url":"https://api.github.com/users/loganfsmyth/repos","events_url":"https://api.github.com/users/loganfsmyth/events{/privacy}","received_events_url":"https://api.github.com/users/loganfsmyth/received_events","type":"User","site_admin":false},"labels":[{"id":311566360,"url":"https://api.github.com/repos/babel/babel/labels/PR:%20Breaking%20Change%20:boom:","name":"PR: Breaking Change :boom:","color":"fbca04","default":false},{"id":148227217,"url":"https://api.github.com/repos/babel/babel/labels/PR:%20Spec%20Compliancy%20:eyeglasses:","name":"PR: Spec Compliancy :eyeglasses:","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":43,"created_at":"2018-03-05T23:17:35Z","updated_at":"2018-03-06T07:48:05Z","closed_at":null,"author_association":"OWNER","pull_request":{"url":"https://api.github.com/repos/babel/babel/pulls/7501","html_url":"https://github.com/babel/babel/pull/7501","diff_url":"https://github.com/babel/babel/pull/7501.diff","patch_url":"https://github.com/babel/babel/pull/7501.patch"},"body":"| Q                        | A <!--(Can use an emoji 👍) -->\r\n| ------------------------ | ---\r\n| Fixed Issues?            | Fixes #6242\r\n| Patch: Bug Fix?          |\r\n| Major: Breaking Change?  | Y\r\n| Minor: New Feature?      |\r\n| Tests Added + Pass?      | Yes\r\n| Documentation PR         | <!-- If so, add `[skip ci]` to your commit message to skip CI -->\r\n| Any Dependency Changes?  |\r\n| License                  | MIT\r\n\r\nAlright, let's have this discussion since #6242 never really took off, and most of my TODOs in there have landed.\r\n\r\nI am of the opinion that Babel 7 should parse `.js` files using the `script` parse goal, and `.mjs` files with the `module` parse goal. In Babel 6, and 7 up to present, the default has been `module`. I also want to make clear that you can still _easily_ set `sourceType:module` in your Babel config to keep the current behavior, but the important question here is the default, because it influences many other parts of Babel's transformations.\r\n\r\nThere are a few primary issues surrounding using `module` as the default:\r\n\r\n* Many perfectly valid Script files will fail to parse. This means that users attempting to run Babel on things in node_modules for instance will fail to parse.\r\n* Defaulting to `module` means Babel converts top-level `this` to `undefined` and injects `use strict`, which can break when run against arbitrary files\r\n* When performing transformations, Babel needs to know whether to inject `import` or `require`, and it does so based on the `sourceType`. Defaulting to `module` means we may inject `import` into valid `CommonJS` modules, breaking them.\r\n* When writing files to disk with `babel-cli` we'd ideally add `.mjs` to files that are modules, and `.js` to scripts. If we default to `module` then we'd potentially output `.mjs` extensions on CommonJS files.\r\n\r\nThese issues become more problematic when you consider that people are more frequently running Babel across arbitrary `node_modules` dependencies. Realistically this pattern is only going to increase in frequency for forseeable future.\r\n\r\nNode now follows this same pattern, with `.js` meaning CommonJS and `.mjs` meaning ESM. There is potential for a field to land in `package.json` that would allow toggling this behavior, and once that lands we could for instance consider a `sourceType: packageMode` option or something, but even with that the default in Node will remain `.js` for CommonJS.\r\n\r\nGiven all of this, it seems like it would be in the best interest of Babel to follow that same pattern, by requiring users to either use `.mjs` or opt into specific ESM behavior in their Babel configuration.\r\n"},"comment":{"url":"https://api.github.com/repos/babel/babel/issues/comments/370692955","html_url":"https://github.com/babel/babel/pull/7501#issuecomment-370692955","issue_url":"https://api.github.com/repos/babel/babel/issues/7501","id":370692955,"user":{"login":"Kovensky","id":73085,"avatar_url":"https://avatars1.githubusercontent.com/u/73085?v=4","gravatar_id":"","url":"https://api.github.com/users/Kovensky","html_url":"https://github.com/Kovensky","followers_url":"https://api.github.com/users/Kovensky/followers","following_url":"https://api.github.com/users/Kovensky/following{/other_user}","gists_url":"https://api.github.com/users/Kovensky/gists{/gist_id}","starred_url":"https://api.github.com/users/Kovensky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kovensky/subscriptions","organizations_url":"https://api.github.com/users/Kovensky/orgs","repos_url":"https://api.github.com/users/Kovensky/repos","events_url":"https://api.github.com/users/Kovensky/events{/privacy}","received_events_url":"https://api.github.com/users/Kovensky/received_events","type":"User","site_admin":false},"created_at":"2018-03-06T07:48:05Z","updated_at":"2018-03-06T07:48:05Z","author_association":"MEMBER","body":"There are also some identifiers that, even if they're not keywords, are only reserved inside modules; the easiest example is `await`. `\"use strict\"; let await;` is a valid script but invalid module."}}
{"actor":{"display_login":"Kovensky"}}