-
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure Ember modules API related globals do not share AST Nodes
The original fix in ember-cli/babel-plugin-ember-modules-api-polyfill#109 attempted to cache the generated member expressions, so that we didn't do duplicated work for each reference to a given global. Unfortunately, this optimization failed to take into consideration that most babel plugins work by directly mutating the node in question. In practice what that meant was that once _any_ usage of a given global was needed to be transformed (e.g. say you had `computed(...args, function(){})` and are transpiling for IE11), then all usages of that global would be mutated. A more concrete example. ```js // input import { computed } from '@ember/object'; function specialComputed(dependentKeys) { return computed(...dependentKeys, function() {}); } function otherLessSpecialComputed() { return computed('stuff', 'hard', 'coded', function() {}); } ``` In this example, the first method (`specialComputed`) needs to be transpiled to something akin to (most of the changes here are from `@babel/plugin-transform-spread`): ```js function specialComputed(dependentKeys) { return Ember.computed.apply(Ember, dependentKeys.concat([function() {}])); } ``` Unfortunately, since the generated `MemberExpression` for `Ember.computed` is shared, this forced the other `computed` usage to be transpiled to: ```js function otherLessSpecialComputed() { return Ember.computed.apply('stuff', 'hard', 'coded', function() {}); } ``` Which is clearly, **totally** invalid. 🤦
- Loading branch information
Showing
2 changed files
with
24 additions
and
176 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