update
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
> Compile ES2015 template literals to ES5
|
||||
|
||||
See our website [@babel/plugin-transform-template-literals](https://babeljs.io/docs/en/next/babel-plugin-transform-template-literals.html) for more information.
|
||||
See our website [@babel/plugin-transform-template-literals](https://babeljs.io/docs/en/babel-plugin-transform-template-literals) for more information.
|
||||
|
||||
## Install
|
||||
|
||||
|
||||
+22
-22
@@ -10,12 +10,13 @@ var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
||||
var _core = require("@babel/core");
|
||||
|
||||
var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
var _api$assumption, _api$assumption2;
|
||||
|
||||
api.assertVersion(7);
|
||||
const {
|
||||
loose
|
||||
} = options;
|
||||
const ignoreToPrimitiveHint = (_api$assumption = api.assumption("ignoreToPrimitiveHint")) != null ? _api$assumption : options.loose;
|
||||
const mutableTemplateObject = (_api$assumption2 = api.assumption("mutableTemplateObject")) != null ? _api$assumption2 : options.loose;
|
||||
let helperName = "taggedTemplateLiteral";
|
||||
if (loose) helperName += "Loose";
|
||||
if (mutableTemplateObject) helperName += "Loose";
|
||||
|
||||
function buildConcatCallExpressions(items) {
|
||||
let avail = true;
|
||||
@@ -64,27 +65,28 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
}
|
||||
}
|
||||
|
||||
const scope = path.scope.getProgramParent();
|
||||
const templateObject = scope.generateUidIdentifier("templateObject");
|
||||
const helperId = this.addHelper(helperName);
|
||||
const callExpressionInput = [_core.types.arrayExpression(strings)];
|
||||
const helperArgs = [_core.types.arrayExpression(strings)];
|
||||
|
||||
if (!isStringsRawEqual) {
|
||||
callExpressionInput.push(_core.types.arrayExpression(raws));
|
||||
helperArgs.push(_core.types.arrayExpression(raws));
|
||||
}
|
||||
|
||||
const lazyLoad = _core.template.ast`
|
||||
function ${templateObject}() {
|
||||
const data = ${_core.types.callExpression(helperId, callExpressionInput)};
|
||||
${templateObject} = function() { return data };
|
||||
return data;
|
||||
}
|
||||
`;
|
||||
scope.path.unshiftContainer("body", lazyLoad);
|
||||
path.replaceWith(_core.types.callExpression(node.tag, [_core.types.callExpression(_core.types.cloneNode(templateObject), []), ...quasi.expressions]));
|
||||
const tmp = path.scope.generateUidIdentifier("templateObject");
|
||||
path.scope.getProgramParent().push({
|
||||
id: _core.types.cloneNode(tmp)
|
||||
});
|
||||
path.replaceWith(_core.types.callExpression(node.tag, [_core.template.expression.ast`
|
||||
${_core.types.cloneNode(tmp)} || (
|
||||
${tmp} = ${this.addHelper(helperName)}(${helperArgs})
|
||||
)
|
||||
`, ...quasi.expressions]));
|
||||
},
|
||||
|
||||
TemplateLiteral(path) {
|
||||
if (path.parent.type === "TSLiteralType") {
|
||||
return;
|
||||
}
|
||||
|
||||
const nodes = [];
|
||||
const expressions = path.get("expressions");
|
||||
let index = 0;
|
||||
@@ -106,15 +108,13 @@ var _default = (0, _helperPluginUtils.declare)((api, options) => {
|
||||
}
|
||||
}
|
||||
|
||||
const considerSecondNode = !loose || !_core.types.isStringLiteral(nodes[1]);
|
||||
|
||||
if (!_core.types.isStringLiteral(nodes[0]) && considerSecondNode) {
|
||||
if (!_core.types.isStringLiteral(nodes[0]) && !(ignoreToPrimitiveHint && _core.types.isStringLiteral(nodes[1]))) {
|
||||
nodes.unshift(_core.types.stringLiteral(""));
|
||||
}
|
||||
|
||||
let root = nodes[0];
|
||||
|
||||
if (loose) {
|
||||
if (ignoreToPrimitiveHint) {
|
||||
for (let i = 1; i < nodes.length; i++) {
|
||||
root = _core.types.binaryExpression("+", root, nodes[i]);
|
||||
}
|
||||
|
||||
+25
-19
@@ -1,52 +1,57 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"@babel/plugin-transform-template-literals@7.10.4",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"@babel/plugin-transform-template-literals@7.18.6",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "@babel/plugin-transform-template-literals@7.10.4",
|
||||
"_id": "@babel/plugin-transform-template-literals@7.10.4",
|
||||
"_from": "@babel/plugin-transform-template-literals@7.18.6",
|
||||
"_id": "@babel/plugin-transform-template-literals@7.18.6",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-4NErciJkAYe+xI5cqfS8pV/0ntlY5N5Ske/4ImxAVX7mk9Rxt2bwDTGv1Msc2BRJvWQcmYEC+yoMLdX22aE4VQ==",
|
||||
"_integrity": "sha512-UuqlRrQmT2SWRvahW46cGSany0uTlcj8NYOS5sRGYi8FxPYPoLd5DDmMd32ZXEj2Jq+06uGVQKHxa/hJx2EzKw==",
|
||||
"_location": "/@babel/plugin-transform-template-literals",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "@babel/plugin-transform-template-literals@7.10.4",
|
||||
"raw": "@babel/plugin-transform-template-literals@7.18.6",
|
||||
"name": "@babel/plugin-transform-template-literals",
|
||||
"escapedName": "@babel%2fplugin-transform-template-literals",
|
||||
"scope": "@babel",
|
||||
"rawSpec": "7.10.4",
|
||||
"rawSpec": "7.18.6",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "7.10.4"
|
||||
"fetchSpec": "7.18.6"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@babel/preset-env"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.10.4.tgz",
|
||||
"_spec": "7.10.4",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.18.6.tgz",
|
||||
"_spec": "7.18.6",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "The Babel Team",
|
||||
"url": "https://babel.dev/team"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/babel/babel/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/helper-annotate-as-pure": "^7.10.4",
|
||||
"@babel/helper-plugin-utils": "^7.10.4"
|
||||
"@babel/helper-plugin-utils": "^7.18.6"
|
||||
},
|
||||
"description": "Compile ES2015 template literals to ES5",
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.10.4",
|
||||
"@babel/helper-plugin-test-runner": "^7.10.4"
|
||||
"@babel/core": "^7.18.6",
|
||||
"@babel/helper-plugin-test-runner": "^7.18.6"
|
||||
},
|
||||
"gitHead": "7fd40d86a0d03ff0e9c3ea16b29689945433d4df",
|
||||
"homepage": "https://github.com/babel/babel#readme",
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-template-literals",
|
||||
"keywords": [
|
||||
"babel-plugin"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"main": "./lib/index.js",
|
||||
"name": "@babel/plugin-transform-template-literals",
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
@@ -59,5 +64,6 @@
|
||||
"url": "git+https://github.com/babel/babel.git",
|
||||
"directory": "packages/babel-plugin-transform-template-literals"
|
||||
},
|
||||
"version": "7.10.4"
|
||||
"type": "commonjs",
|
||||
"version": "7.18.6"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user