Merge pull request #1382 from kondi/jscript
add optional jscript transformer for basic IE8 compatibility (fixes #1369)
This commit is contained in:
commit
56437f94bc
@ -115,5 +115,6 @@ export default {
|
||||
"utility.inlineExpressions": require("./utility/inline-expressions"),
|
||||
"utility.deadCodeElimination": require("./utility/dead-code-elimination"),
|
||||
|
||||
jscript: require("./other/jscript"),
|
||||
flow: require("./other/flow")
|
||||
};
|
||||
|
||||
27
src/babel/transformation/transformers/other/jscript.js
Normal file
27
src/babel/transformation/transformers/other/jscript.js
Normal file
@ -0,0 +1,27 @@
|
||||
import * as t from "../../../types";
|
||||
|
||||
export var metadata = {
|
||||
optional: true
|
||||
};
|
||||
|
||||
export function VariableDeclarator(node, print) {
|
||||
var varName = node.id.name;
|
||||
if (node.init) {
|
||||
if (t.isFunctionExpression(node.init)) {
|
||||
if (node.init.id) {
|
||||
var fnName = node.init.id.name;
|
||||
if (varName === fnName) {
|
||||
node.init._ignoreUserWhitespace = true;
|
||||
var closureBody = [
|
||||
t.toStatement(node.init),
|
||||
t.returnStatement(node.init.id)
|
||||
];
|
||||
var init = t.callExpression(
|
||||
t.functionExpression(null, [], t.blockStatement(closureBody)), []
|
||||
);
|
||||
return t.variableDeclarator(node.id, init);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
test/core/fixtures/transformation/jscript/options.json
Normal file
3
test/core/fixtures/transformation/jscript/options.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"optional": ["jscript"]
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
class Test {
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
"use strict";
|
||||
|
||||
var Test = (function () {
|
||||
function Test() {
|
||||
babelHelpers.classCallCheck(this, Test);
|
||||
}
|
||||
|
||||
return Test;
|
||||
})();
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"externalHelpers": true
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
var IdenticalName = function IdenticalName(x) {
|
||||
return x;
|
||||
};
|
||||
|
||||
var DifferentNameA = function DifferentNameB(x) {
|
||||
return x;
|
||||
};
|
||||
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
var IdenticalName = (function () {
|
||||
function IdenticalName(x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
return IdenticalName;
|
||||
})();
|
||||
|
||||
var DifferentNameA = function DifferentNameB(x) {
|
||||
return x;
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user