File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
babel-plugin-minify-builtins/src
babel-preset-babili/__tests__ Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -78,15 +78,13 @@ module.exports = function({ types: t }) {
78
78
if ( subpaths . length <= 1 ) {
79
79
continue ;
80
80
}
81
- const uniqueIdentifier = this . program . scope . generateUidIdentifier (
82
- expName
83
- ) ;
81
+ const uniqueIdentifier = parent . scope . generateUidIdentifier ( expName ) ;
84
82
const newNode = t . variableDeclaration ( "var" , [
85
83
t . variableDeclarator ( uniqueIdentifier , subpaths [ 0 ] . node )
86
84
] ) ;
87
85
88
86
for ( const path of subpaths ) {
89
- path . replaceWith ( uniqueIdentifier ) ;
87
+ path . replaceWith ( t . clone ( uniqueIdentifier ) ) ;
90
88
}
91
89
// hoist the created var to the top of the function scope
92
90
parent . get ( "body" ) . unshiftContainer ( "body" , newNode ) ;
Original file line number Diff line number Diff line change @@ -131,4 +131,20 @@ describe("preset", () => {
131
131
` ) ;
132
132
expect ( transform ( source ) ) . toBe ( expected ) ;
133
133
} ) ;
134
+
135
+ it ( "should fix bug#568 - conflicts b/w builtIns and mangle" , ( ) => {
136
+ const source = unpad ( `
137
+ (function () {
138
+ return [Math.pi, Math.pi];
139
+ })();
140
+ ` ) ;
141
+ const expected = unpad ( `
142
+ (function () {
143
+ var a = Math.pi;
144
+
145
+ return [a, a];
146
+ })();
147
+ ` ) ;
148
+ expect ( transform ( source ) ) . toBe ( expected ) ;
149
+ } ) ;
134
150
} ) ;
You can’t perform that action at this time.
0 commit comments