Support Babel 8 alongside Babel 7 - #720
Draft
wagenet wants to merge 1 commit into
Draft
Conversation
Babel 8 parses `import()` into an ImportExpression node instead of a CallExpression with an `Import` callee, so both of our babel plugins silently stopped seeing dynamic imports. They now handle both shapes, with a regression test that uses Babel 7's `createImportExpressions` parser option to produce the Babel 8 AST. In cleanBabelConfig, swap the proposal-* class-features plugins for the maintained transform-* equivalents (no Babel 8 release of the proposal packages exists), pass decorators `version: 'legacy'` instead of the `legacy` shorthand Babel 8 dropped, and stop passing `loose: false`, which is both the default and deprecated in Babel 8. Widen the babel dependency ranges to `^7.x || ^8.0.0` and babel-loader to include ^10.1.1, the first release whose @babel/core peer admits 8. Add ts/babel-compat.ts because Babel 8 ships its own types under different names, which otherwise breaks tsc. The full scenario suite can't run under Babel 8 until ember-cli-babel supports it, so the new unit_babel8 CI job covers the part we own. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes ember-auto-import install and run under either
@babel/core7 or 8. I didn't find an existing Babel 8 issue in this repo.The bug that breaks silently
Babel 8 parses
import()into a dedicatedImportExpressionnode instead of aCallExpressionwith anImportcallee. Both of our plugins keyed off the old shape:analyzer-plugin.tscheckedcallee.type === 'Import', andbabel-plugin.tshad anImportvisitor.Under Babel 8 neither fires, and nothing throws. The analyzer stops seeing dynamic imports, so those deps never enter a bundle, and
import()is never rewritten toemberAutoImportDynamic. You'd find out at runtime.Both plugins now handle both shapes. Babel 7.22+ can emit the Babel 8 AST via the
createImportExpressionsparser option, so the regression test runs on our normal Babel 7 CI. It fails without the fix.Config Babel 8 rejects
In
cleanBabelConfig():plugin-proposal-class-propertiesplugin-transform-class-properties@babel/core: ^7.0.0-0peer is an install failure against core 8plugin-proposal-private-methodsplugin-transform-private-methods{ legacy: true }{ version: 'legacy' }version. 7.17+ acceptsversion: 'legacy'{ loose: false }assumptionsRanges
Babel deps widened to
^7.x || ^8.0.0. Babel 8's plugins declareapi.assertVersion("^7.0.0-0 || ^8.0.0"), so a mixed install (core 7 with plugins 8, which is what pnpm produces here) works.babel-loadergoes to^8.0.6 || ^10.1.1; 8 and 9 both cap@babel/coreat^7. Two side effects worth a look: a fresh install now resolves babel-loader 10 even for Babel 7 users, and itsengines(^18.20.0 || ^20.10.0 || >=22.0.0) are narrower than this package's declared12.* || 14.* || >= 16. Thatenginesfield looked stale enough that I left it alone.broccoli-babel-transpiler: ^8.0.0is new in devDependencies. The unit tests imported it without declaring it and were getting 7.8.1 by hoisting, which callsbabel.transform()with no callback, which Babel 8 rejects. 8.0.2 needsnewand{ babel: options }, hence the test churn.TypeScript
Babel 8 ships its own types and renamed things (
TransformOptionstoInputOptions,PluginObjtoPluginObject), sotscfails outright under it.ts/babel-compat.tsderives the options type from a signature present in both.cleanBabelConfig's plugin list is nowPluginItem[], which meant flattening single-element[plugin]entries to bare strings.Test results
Under
@babel/core8.0.1,preset-env8.0.2, babel-loader 10.1.1 (forced withpnpm.overrides): 157/157 node unit tests pass. That's the signal that matters, sincejs/testsdrives both plugins and the analyzer through real@babel/core. The newunit_babel8CI job runs exactly this.Babel 7 is unregressed: 157/157 unit tests, plus the
release-babel,release-dynamic-import,release-static-import,release-import-sync, andindirect-analyzer-skewscenarios.The full scenario suite can't run under Babel 8 yet, and the blocker isn't here. It dies in ember-cli-babel 8.3.1, which still passes four removed options:
{ legacy: true }to proposal-decorators,{ legacy: true }to transform-class-static-block (which has no such option),regenerator/useESModulesto transform-runtime, andmoduleId/getModuleId. I patched the first three innode_modulesto get further; the build then failed ongetModuleIdinside a nestedqunit-dom/node_modules/ember-cli-babela local patch can't reach.Left alone
analyzer.tshasif (this.pack.babelMajorVersion !== 7) throwon the slow analyzer path. That's the ember-cli-babel major, not@babel/core's, so it already throws for anyone on ember-cli-babel 8 who reaches that path. Unrelated to Babel 8, but someone should look at it.babel-plugin-syntax-dynamic-importis a Babel 6 plugin pushing adynamicImportparser plugin name. Babel 8 ignores it rather than erroring, so it's harmless.🤖 Generated with Claude Code