-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Adds an option to emit external babel helpers
This PR adds the `includeExternalHelpers` config option which allows users to explicitly opt into using externalized helpers for transpiled code. In large apps this can help with app size, especially in apps which are making heavy usage of new ES features like native classes and decorators. This option is a _global_ option, meaning it _must_ be configured in the root application. The reason for this is because there must be one canonical source of truth for which version of helpers are being used, and whether or not helpers are being used at all. If one addon decides to use helpers, the app must include them, and they must be the right version. The current setup will _only_ support babel 7 helpers. This can be expanded upon in the future, but the complexity of doing so makes it beyond the scope of the initial work here.
- Loading branch information
Showing
10 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
let { addNamed } = require('@babel/helper-module-imports') | ||
|
||
module.exports = function injectBabelHelpers(options) { | ||
const { helperVersion = "7.0.0-beta.0" } = options; | ||
|
||
return { | ||
pre(file) { | ||
file.set('helperGenerator', name => { | ||
// If the helper didn't exist yet at the version given, we bail | ||
// out and let Babel either insert it directly, or throw an error | ||
// so that plugins can handle that case properly. | ||
if ( | ||
file.availableHelper && | ||
!file.availableHelper(name, helperVersion) | ||
) { | ||
return; | ||
} | ||
|
||
return addNamed(file.path, name, 'ember-cli-babel/-private/helpers'); | ||
}); | ||
}, | ||
}; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
/* eslint-env node */ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | external helpers test', function() { | ||
test('external helpers work ', function(assert) { | ||
assert.expect(0); | ||
|
||
// This test will transpile to use external helpers depending on targets. If | ||
// those helpers are not present, it will break. If IE11 is removed from | ||
// targets we should find another way to test this. | ||
class Foo {} | ||
|
||
new Foo(); | ||
}); | ||
}); |
This file contains 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