Skip to content

Commit cba0f03

Browse files
alunnyrxaviers
authored andcommitted
Transforms: Support babel6
A change in the output from Babel 6 emits default transforms as `module.default` rather than `module["default"]`. This changes the shape of the node that globalize-compiler examines. Closes #12
1 parent ff2b2cc commit cba0f03

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Diff for: lib/extract-transforms/babel-globalize2-default-into-globalize.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@ var esprima = require( "esprima" );
22

33
var Syntax = esprima.Syntax;
44

5+
function isDefaultProperty(prop) {
6+
return (prop.type === Syntax.Literal && prop.value === "default") ||
7+
(prop.type === Syntax.Identifier && prop.name === "default");
8+
}
9+
510
/**
6-
* Transform `_globalize2["default"].<fn>` (commonly generated by babel when transpiling ES6) into
7-
* `Globalize.<fn>`.
11+
* Transform `_globalize2["default"].<fn>` or `_globalize2.default.<fn>`
12+
* (commonly generated by babel when transpiling ES6) into `Globalize.<fn>`.
813
*/
914
module.exports = {
1015
test: function( node ) {
@@ -13,8 +18,7 @@ module.exports = {
1318
node.callee.object.type === Syntax.MemberExpression &&
1419
node.callee.object.object.type === Syntax.Identifier &&
1520
node.callee.object.object.name === "_globalize2" &&
16-
node.callee.object.property.type === Syntax.Literal &&
17-
node.callee.object.property.value === "default";
21+
isDefaultProperty(node.callee.object.property);
1822
},
1923

2024
transform: function( node ) {

0 commit comments

Comments
 (0)