@@ -11,20 +11,7 @@ module.exports = function (babel) {
1111
1212 const MODULE = '@glimmer/tracking' ;
1313 const IMPORT = 'cached' ;
14- const GLOBAL = 'Ember._cached' ;
15- const MEMBER_EXPRESSION = t . MemberExpression (
16- t . identifier ( 'Ember' ) ,
17- t . identifier ( '_cached' )
18- ) ;
19-
20- const TSTypesRequiringModification = [
21- 'TSAsExpression' ,
22- 'TSTypeAssertion' ,
23- 'TSNonNullExpression'
24- ] ;
25- const isTypescriptNode = node =>
26- node . type . startsWith ( 'TS' ) &&
27- ! TSTypesRequiringModification . includes ( node . type ) ;
14+ const REPLACED_MODULE = 'ember-cached-decorator-polyfill' ;
2815
2916 return {
3017 name : 'ember-cache-decorator-polyfill' ,
@@ -74,30 +61,17 @@ module.exports = function (babel) {
7461
7562 removals . push ( specifierPath ) ;
7663
77- if (
78- path . scope . bindings [ local . name ] . referencePaths . find (
79- rp => rp . parent . type === 'ExportSpecifier'
80- )
81- ) {
82- // not safe to use path.scope.rename directly
83- declarations . push (
84- t . variableDeclaration ( 'var' , [
85- t . variableDeclarator (
64+ declarations . push (
65+ t . importDeclaration (
66+ [
67+ t . importSpecifier (
8668 t . identifier ( local . name ) ,
87- t . identifier ( GLOBAL )
69+ t . identifier ( IMPORT )
8870 )
89- ] )
90- ) ;
91- } else {
92- // Replace the occurences of the imported name with the global name.
93- let binding = path . scope . getBinding ( local . name ) ;
94-
95- binding . referencePaths . forEach ( referencePath => {
96- if ( ! isTypescriptNode ( referencePath . parentPath ) ) {
97- referencePath . replaceWith ( MEMBER_EXPRESSION ) ;
98- }
99- } ) ;
100- }
71+ ] ,
72+ t . stringLiteral ( REPLACED_MODULE )
73+ )
74+ ) ;
10175 } ) ;
10276 }
10377
@@ -109,69 +83,6 @@ module.exports = function (babel) {
10983 path . insertAfter ( declarations ) ;
11084 }
11185 }
112- } ,
113-
114- ExportNamedDeclaration ( path ) {
115- let node = path . node ;
116- if ( ! node . source ) {
117- return ;
118- }
119-
120- let replacements = [ ] ;
121- let removals = [ ] ;
122- let specifiers = path . get ( 'specifiers' ) ;
123- let importPath = node . source . value ;
124-
125- // Only walk specifiers if this is a module we have a mapping for
126- if ( importPath === MODULE ) {
127- // Iterate all the specifiers and attempt to locate their mapping
128- specifiers . forEach ( specifierPath => {
129- let specifier = specifierPath . node ;
130-
131- // exported is the name of the module being export,
132- // e.g. `foo` in `export { computed as foo } from '@ember/object';`
133- const exported = specifier . exported ;
134-
135- // local is the original name of the module, this is usually the same
136- // as the exported value, unless the module is aliased
137- const local = specifier . local ;
138-
139- // We only care about the ExportSpecifier
140- if ( specifier . type !== 'ExportSpecifier' ) {
141- return ;
142- }
143-
144- // Determine the import name, either default or named
145- let importName = local . name ;
146-
147- if ( importName !== IMPORT ) return ;
148-
149- removals . push ( specifierPath ) ;
150-
151- let declaration ;
152- const globalAsIdentifier = t . identifier ( GLOBAL ) ;
153- if ( exported . name === 'default' ) {
154- declaration = t . exportDefaultDeclaration ( globalAsIdentifier ) ;
155- } else {
156- // Replace the node with a new `var name = Ember.something`
157- declaration = t . exportNamedDeclaration (
158- t . variableDeclaration ( 'var' , [
159- t . variableDeclarator ( exported , globalAsIdentifier )
160- ] ) ,
161- [ ] ,
162- null
163- ) ;
164- }
165- replacements . push ( declaration ) ;
166- } ) ;
167- }
168-
169- if ( removals . length > 0 && removals . length === node . specifiers . length ) {
170- path . replaceWithMultiple ( replacements ) ;
171- } else if ( replacements . length > 0 ) {
172- removals . forEach ( specifierPath => specifierPath . remove ( ) ) ;
173- path . insertAfter ( replacements ) ;
174- }
17586 }
17687 }
17788 } ;
0 commit comments