Declare template objects inline (#12588)
This commit is contained in:
parent
ed90f17978
commit
fb12afc289
@ -4,14 +4,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
||||
|
||||
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
||||
|
||||
function _templateObject() {
|
||||
const data = (0, _taggedTemplateLiteral2.default)(["foo"]);
|
||||
var _templateObject;
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
tag(_templateObject());
|
||||
tag(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["foo"])));
|
||||
|
||||
@ -4,14 +4,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
||||
|
||||
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
||||
|
||||
function _templateObject() {
|
||||
const data = (0, _taggedTemplateLiteral2.default)(["foo"]);
|
||||
var _templateObject;
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
tag(_templateObject());
|
||||
tag(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["foo"])));
|
||||
|
||||
@ -73,29 +73,22 @@ export default declare((api, options) => {
|
||||
}
|
||||
}
|
||||
|
||||
const scope = path.scope.getProgramParent();
|
||||
const templateObject = scope.generateUidIdentifier("templateObject");
|
||||
|
||||
const helperId = this.addHelper(helperName);
|
||||
const callExpressionInput = [t.arrayExpression(strings)];
|
||||
|
||||
const helperArgs = [t.arrayExpression(strings)];
|
||||
// only add raw arrayExpression if there is any difference between raws and strings
|
||||
if (!isStringsRawEqual) {
|
||||
callExpressionInput.push(t.arrayExpression(raws));
|
||||
helperArgs.push(t.arrayExpression(raws));
|
||||
}
|
||||
|
||||
const lazyLoad = template.ast`
|
||||
function ${templateObject}() {
|
||||
const data = ${t.callExpression(helperId, callExpressionInput)};
|
||||
${t.cloneNode(templateObject)} = function() { return data };
|
||||
return data;
|
||||
}
|
||||
`;
|
||||
const tmp = path.scope.generateUidIdentifier("templateObject");
|
||||
path.scope.getProgramParent().push({ id: t.cloneNode(tmp) });
|
||||
|
||||
scope.path.unshiftContainer("body", lazyLoad);
|
||||
path.replaceWith(
|
||||
t.callExpression(node.tag, [
|
||||
t.callExpression(t.cloneNode(templateObject), []),
|
||||
template.expression.ast`
|
||||
${t.cloneNode(tmp)} || (
|
||||
${tmp} = ${this.addHelper(helperName)}(${helperArgs})
|
||||
)
|
||||
`,
|
||||
...quasi.expressions,
|
||||
]),
|
||||
);
|
||||
|
||||
@ -1,33 +1,15 @@
|
||||
function _templateObject2() {
|
||||
const data = _taggedTemplateLiteral(["some template"]);
|
||||
|
||||
_templateObject2 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject() {
|
||||
const data = _taggedTemplateLiteral(["some template"]);
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject, _templateObject2;
|
||||
|
||||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
||||
|
||||
var tag = v => v;
|
||||
|
||||
function foo() {
|
||||
return tag(_templateObject());
|
||||
return tag(_templateObject || (_templateObject = _taggedTemplateLiteral(["some template"])));
|
||||
}
|
||||
|
||||
function bar() {
|
||||
return tag(_templateObject2());
|
||||
return tag(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["some template"])));
|
||||
}
|
||||
|
||||
expect(foo()).toBe(foo());
|
||||
|
||||
@ -1,24 +1,6 @@
|
||||
function _templateObject2() {
|
||||
const data = _taggedTemplateLiteral(["first", "second"]);
|
||||
|
||||
_templateObject2 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject() {
|
||||
const data = _taggedTemplateLiteral(["wow"]);
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject, _templateObject2;
|
||||
|
||||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
||||
|
||||
var foo = tag(_templateObject());
|
||||
var bar = tag(_templateObject2(), 1);
|
||||
var foo = tag(_templateObject || (_templateObject = _taggedTemplateLiteral(["wow"])));
|
||||
var bar = tag(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["first", "second"])), 1);
|
||||
|
||||
@ -1,13 +1,5 @@
|
||||
function _templateObject() {
|
||||
const data = _taggedTemplateLiteral(["aa\uD835\uDC9C\uD835\uDC9C"], ["\\u0061\\u{0061}\\ud835\\udc9c\\u{1d49c}"]);
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject;
|
||||
|
||||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
||||
|
||||
var foo = bar(_templateObject());
|
||||
var foo = bar(_templateObject || (_templateObject = _taggedTemplateLiteral(["aa\uD835\uDC9C\uD835\uDC9C"], ["\\u0061\\u{0061}\\ud835\\udc9c\\u{1d49c}"])));
|
||||
|
||||
@ -1,35 +1,7 @@
|
||||
function _templateObject3() {
|
||||
const data = _taggedTemplateLiteral(["wow\naB", " ", ""], ["wow\\naB", " ", ""]);
|
||||
|
||||
_templateObject3 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject2() {
|
||||
const data = _taggedTemplateLiteral(["wow\nab", " ", ""], ["wow\\nab", " ", ""]);
|
||||
|
||||
_templateObject2 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject() {
|
||||
const data = _taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""]);
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject, _templateObject2, _templateObject3;
|
||||
|
||||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
||||
|
||||
var foo = bar(_templateObject(), 42, _.foobar());
|
||||
var bar = bar(_templateObject2(), 42, _.foobar());
|
||||
var bar = bar(_templateObject3(), 42, _.baz());
|
||||
var foo = bar(_templateObject || (_templateObject = _taggedTemplateLiteral(["wow\na", "b ", ""], ["wow\\na", "b ", ""])), 42, _.foobar());
|
||||
var bar = bar(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["wow\nab", " ", ""], ["wow\\nab", " ", ""])), 42, _.foobar());
|
||||
var bar = bar(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["wow\naB", " ", ""], ["wow\\naB", " ", ""])), 42, _.baz());
|
||||
|
||||
@ -1,94 +1,16 @@
|
||||
function _templateObject8() {
|
||||
const data = _taggedTemplateLiteral([void 0], ["\\01"]);
|
||||
|
||||
_templateObject8 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject7() {
|
||||
const data = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\u{-0}", "right"]);
|
||||
|
||||
_templateObject7 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject6() {
|
||||
const data = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\u000g", "right"]);
|
||||
|
||||
_templateObject6 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject5() {
|
||||
const data = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\xg", "right"]);
|
||||
|
||||
_templateObject5 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject4() {
|
||||
const data = _taggedTemplateLiteral(["left", void 0], ["left", "\\xg"]);
|
||||
|
||||
_templateObject4 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject3() {
|
||||
const data = _taggedTemplateLiteral([void 0, "right"], ["\\xg", "right"]);
|
||||
|
||||
_templateObject3 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject2() {
|
||||
const data = _taggedTemplateLiteral([void 0], ["\\01"]);
|
||||
|
||||
_templateObject2 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject() {
|
||||
const data = _taggedTemplateLiteral([void 0], ["\\unicode and \\u{55}"]);
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
|
||||
|
||||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
||||
|
||||
tag(_templateObject());
|
||||
tag(_templateObject2());
|
||||
tag(_templateObject3(), 0);
|
||||
tag(_templateObject4(), 0);
|
||||
tag(_templateObject5(), 0, 1);
|
||||
tag(_templateObject6(), 0, 1);
|
||||
tag(_templateObject7(), 0, 1);
|
||||
tag(_templateObject || (_templateObject = _taggedTemplateLiteral([void 0], ["\\unicode and \\u{55}"])));
|
||||
tag(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral([void 0], ["\\01"])));
|
||||
tag(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral([void 0, "right"], ["\\xg", "right"])), 0);
|
||||
tag(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["left", void 0], ["left", "\\xg"])), 0);
|
||||
tag(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\xg", "right"])), 0, 1);
|
||||
tag(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\u000g", "right"])), 0, 1);
|
||||
tag(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["left", void 0, "right"], ["left", "\\u{-0}", "right"])), 0, 1);
|
||||
|
||||
function a() {
|
||||
var undefined = 4;
|
||||
tag(_templateObject8());
|
||||
tag(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral([void 0], ["\\01"])));
|
||||
}
|
||||
|
||||
@ -1,35 +1,7 @@
|
||||
function _templateObject3() {
|
||||
const data = _taggedTemplateLiteralLoose(["wow\naB", " ", ""], ["wow\\naB", " ", ""]);
|
||||
|
||||
_templateObject3 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject2() {
|
||||
const data = _taggedTemplateLiteralLoose(["wow\nab", " ", ""], ["wow\\nab", " ", ""]);
|
||||
|
||||
_templateObject2 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject() {
|
||||
const data = _taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""]);
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject, _templateObject2, _templateObject3;
|
||||
|
||||
function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
|
||||
|
||||
var foo = bar(_templateObject(), 42, _.foobar());
|
||||
var bar = bar(_templateObject2(), 42, _.foobar());
|
||||
var bar = bar(_templateObject3(), 42, _.baz());
|
||||
var foo = bar(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["wow\na", "b ", ""], ["wow\\na", "b ", ""])), 42, _.foobar());
|
||||
var bar = bar(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["wow\nab", " ", ""], ["wow\\nab", " ", ""])), 42, _.foobar());
|
||||
var bar = bar(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["wow\naB", " ", ""], ["wow\\naB", " ", ""])), 42, _.baz());
|
||||
|
||||
@ -1,94 +1,16 @@
|
||||
function _templateObject8() {
|
||||
const data = _taggedTemplateLiteralLoose([void 0], ["\\01"]);
|
||||
|
||||
_templateObject8 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject7() {
|
||||
const data = _taggedTemplateLiteralLoose(["left", void 0, "right"], ["left", "\\u{-0}", "right"]);
|
||||
|
||||
_templateObject7 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject6() {
|
||||
const data = _taggedTemplateLiteralLoose(["left", void 0, "right"], ["left", "\\u000g", "right"]);
|
||||
|
||||
_templateObject6 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject5() {
|
||||
const data = _taggedTemplateLiteralLoose(["left", void 0, "right"], ["left", "\\xg", "right"]);
|
||||
|
||||
_templateObject5 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject4() {
|
||||
const data = _taggedTemplateLiteralLoose(["left", void 0], ["left", "\\xg"]);
|
||||
|
||||
_templateObject4 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject3() {
|
||||
const data = _taggedTemplateLiteralLoose([void 0, "right"], ["\\xg", "right"]);
|
||||
|
||||
_templateObject3 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject2() {
|
||||
const data = _taggedTemplateLiteralLoose([void 0], ["\\01"]);
|
||||
|
||||
_templateObject2 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject() {
|
||||
const data = _taggedTemplateLiteralLoose([void 0], ["\\unicode and \\u{55}"]);
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
|
||||
|
||||
function _taggedTemplateLiteralLoose(strings, raw) { if (!raw) { raw = strings.slice(0); } strings.raw = raw; return strings; }
|
||||
|
||||
tag(_templateObject());
|
||||
tag(_templateObject2());
|
||||
tag(_templateObject3(), 0);
|
||||
tag(_templateObject4(), 0);
|
||||
tag(_templateObject5(), 0, 1);
|
||||
tag(_templateObject6(), 0, 1);
|
||||
tag(_templateObject7(), 0, 1);
|
||||
tag(_templateObject || (_templateObject = _taggedTemplateLiteralLoose([void 0], ["\\unicode and \\u{55}"])));
|
||||
tag(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose([void 0], ["\\01"])));
|
||||
tag(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose([void 0, "right"], ["\\xg", "right"])), 0);
|
||||
tag(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["left", void 0], ["left", "\\xg"])), 0);
|
||||
tag(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["left", void 0, "right"], ["left", "\\xg", "right"])), 0, 1);
|
||||
tag(_templateObject6 || (_templateObject6 = _taggedTemplateLiteralLoose(["left", void 0, "right"], ["left", "\\u000g", "right"])), 0, 1);
|
||||
tag(_templateObject7 || (_templateObject7 = _taggedTemplateLiteralLoose(["left", void 0, "right"], ["left", "\\u{-0}", "right"])), 0, 1);
|
||||
|
||||
function a() {
|
||||
var undefined = 4;
|
||||
tag(_templateObject8());
|
||||
tag(_templateObject8 || (_templateObject8 = _taggedTemplateLiteralLoose([void 0], ["\\01"])));
|
||||
}
|
||||
|
||||
@ -1,57 +1,9 @@
|
||||
function _templateObject5() {
|
||||
const data = _taggedTemplateLiteral(["\\\\u{1d49c}"], ["\\\\\\\\u{1d49c}"]);
|
||||
|
||||
_templateObject5 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject4() {
|
||||
const data = _taggedTemplateLiteral(["\\\uD835\uDC9C"], ["\\\\\\u{1d49c}"]);
|
||||
|
||||
_templateObject4 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject3() {
|
||||
const data = _taggedTemplateLiteral(["\\u{1d49c}"], ["\\\\u{1d49c}"]);
|
||||
|
||||
_templateObject3 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject2() {
|
||||
const data = _taggedTemplateLiteral(["\uD835\uDC9C"], ["\\u{1d49c}"]);
|
||||
|
||||
_templateObject2 = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function _templateObject() {
|
||||
const data = _taggedTemplateLiteral(["\uD835\uDC9C\uD835\uDC9C\uD835\uDC9C"], ["\uD835\uDC9C\\ud835\\udc9c\\u{1d49c}"]);
|
||||
|
||||
_templateObject = function () {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
||||
|
||||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
||||
|
||||
test(_templateObject());
|
||||
test(_templateObject2());
|
||||
test(_templateObject3());
|
||||
test(_templateObject4());
|
||||
test(_templateObject5());
|
||||
test(_templateObject || (_templateObject = _taggedTemplateLiteral(["\uD835\uDC9C\uD835\uDC9C\uD835\uDC9C"], ["\uD835\uDC9C\\ud835\\udc9c\\u{1d49c}"])));
|
||||
test(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\uD835\uDC9C"], ["\\u{1d49c}"])));
|
||||
test(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\\u{1d49c}"], ["\\\\u{1d49c}"])));
|
||||
test(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\\\uD835\uDC9C"], ["\\\\\\u{1d49c}"])));
|
||||
test(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\\\\u{1d49c}"], ["\\\\\\\\u{1d49c}"])));
|
||||
|
||||
@ -1,13 +1,5 @@
|
||||
function _templateObject() {
|
||||
var data = _taggedTemplateLiteral(["Safari 12 borked"]);
|
||||
|
||||
_templateObject = function _templateObject() {
|
||||
return data;
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
var _templateObject;
|
||||
|
||||
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
||||
|
||||
tag(_templateObject());
|
||||
tag(_templateObject || (_templateObject = _taggedTemplateLiteral(["Safari 12 borked"])));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user