diff options
Diffstat (limited to 'node_modules/@babel/plugin-transform-template-literals')
5 files changed, 185 insertions, 0 deletions
diff --git a/node_modules/@babel/plugin-transform-template-literals/LICENSE b/node_modules/@babel/plugin-transform-template-literals/LICENSE new file mode 100644 index 00000000..f31575ec --- /dev/null +++ b/node_modules/@babel/plugin-transform-template-literals/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2014-present Sebastian McKenzie and other contributors + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/@babel/plugin-transform-template-literals/README.md b/node_modules/@babel/plugin-transform-template-literals/README.md new file mode 100644 index 00000000..f0176f2a --- /dev/null +++ b/node_modules/@babel/plugin-transform-template-literals/README.md @@ -0,0 +1,19 @@ +# @babel/plugin-transform-template-literals + +> Compile ES2015 template literals to ES5 + +See our website [@babel/plugin-transform-template-literals](https://babeljs.io/docs/en/babel-plugin-transform-template-literals) for more information. + +## Install + +Using npm: + +```sh +npm install --save-dev @babel/plugin-transform-template-literals +``` + +or using yarn: + +```sh +yarn add @babel/plugin-transform-template-literals --dev +``` diff --git a/node_modules/@babel/plugin-transform-template-literals/lib/index.js b/node_modules/@babel/plugin-transform-template-literals/lib/index.js new file mode 100644 index 00000000..23456925 --- /dev/null +++ b/node_modules/@babel/plugin-transform-template-literals/lib/index.js @@ -0,0 +1,109 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.default = void 0; +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 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 (mutableTemplateObject) helperName += "Loose"; + function buildConcatCallExpressions(items) { + let avail = true; + return items.reduce(function (left, right) { + let canBeInserted = _core.types.isLiteral(right); + if (!canBeInserted && avail) { + canBeInserted = true; + avail = false; + } + if (canBeInserted && _core.types.isCallExpression(left)) { + left.arguments.push(right); + return left; + } + return _core.types.callExpression(_core.types.memberExpression(left, _core.types.identifier("concat")), [right]); + }); + } + return { + name: "transform-template-literals", + visitor: { + TaggedTemplateExpression(path) { + const { + node + } = path; + const { + quasi + } = node; + const strings = []; + const raws = []; + let isStringsRawEqual = true; + for (const elem of quasi.quasis) { + const { + raw, + cooked + } = elem.value; + const value = cooked == null ? path.scope.buildUndefinedNode() : _core.types.stringLiteral(cooked); + strings.push(value); + raws.push(_core.types.stringLiteral(raw)); + if (raw !== cooked) { + isStringsRawEqual = false; + } + } + const helperArgs = [_core.types.arrayExpression(strings)]; + if (!isStringsRawEqual) { + helperArgs.push(_core.types.arrayExpression(raws)); + } + 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; + for (const elem of path.node.quasis) { + if (elem.value.cooked) { + nodes.push(_core.types.stringLiteral(elem.value.cooked)); + } + if (index < expressions.length) { + const expr = expressions[index++]; + const node = expr.node; + if (!_core.types.isStringLiteral(node, { + value: "" + })) { + nodes.push(node); + } + } + } + if (!_core.types.isStringLiteral(nodes[0]) && !(ignoreToPrimitiveHint && _core.types.isStringLiteral(nodes[1]))) { + nodes.unshift(_core.types.stringLiteral("")); + } + let root = nodes[0]; + if (ignoreToPrimitiveHint) { + for (let i = 1; i < nodes.length; i++) { + root = _core.types.binaryExpression("+", root, nodes[i]); + } + } else if (nodes.length > 1) { + root = buildConcatCallExpressions(nodes); + } + path.replaceWith(root); + } + } + }; +}); +exports.default = _default; + +//# sourceMappingURL=index.js.map diff --git a/node_modules/@babel/plugin-transform-template-literals/lib/index.js.map b/node_modules/@babel/plugin-transform-template-literals/lib/index.js.map new file mode 100644 index 00000000..9c07c7f1 --- /dev/null +++ b/node_modules/@babel/plugin-transform-template-literals/lib/index.js.map @@ -0,0 +1 @@ +{"version":3,"names":["_helperPluginUtils","require","_core","_default","declare","api","options","_api$assumption","_api$assumption2","assertVersion","ignoreToPrimitiveHint","assumption","loose","mutableTemplateObject","helperName","buildConcatCallExpressions","items","avail","reduce","left","right","canBeInserted","t","isLiteral","isCallExpression","arguments","push","callExpression","memberExpression","identifier","name","visitor","TaggedTemplateExpression","path","node","quasi","strings","raws","isStringsRawEqual","elem","quasis","raw","cooked","value","scope","buildUndefinedNode","stringLiteral","helperArgs","arrayExpression","tmp","generateUidIdentifier","getProgramParent","id","cloneNode","replaceWith","tag","template","expression","ast","addHelper","expressions","TemplateLiteral","parent","type","nodes","get","index","length","expr","isStringLiteral","unshift","root","i","binaryExpression","exports","default"],"sources":["../src/index.ts"],"sourcesContent":["import { declare } from \"@babel/helper-plugin-utils\";\nimport { template, types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\n\nexport interface Options {\n loose?: boolean;\n}\n\nexport default declare((api, options: Options) => {\n api.assertVersion(7);\n\n const ignoreToPrimitiveHint =\n api.assumption(\"ignoreToPrimitiveHint\") ?? options.loose;\n const mutableTemplateObject =\n api.assumption(\"mutableTemplateObject\") ?? options.loose;\n\n let helperName = \"taggedTemplateLiteral\";\n if (mutableTemplateObject) helperName += \"Loose\";\n\n /**\n * This function groups the objects into multiple calls to `.concat()` in\n * order to preserve execution order of the primitive conversion, e.g.\n *\n * \"\".concat(obj.foo, \"foo\", obj2.foo, \"foo2\")\n *\n * would evaluate both member expressions _first_ then, `concat` will\n * convert each one to a primitive, whereas\n *\n * \"\".concat(obj.foo, \"foo\").concat(obj2.foo, \"foo2\")\n *\n * would evaluate the member, then convert it to a primitive, then evaluate\n * the second member and convert that one, which reflects the spec behavior\n * of template literals.\n */\n function buildConcatCallExpressions(items: t.Expression[]): t.CallExpression {\n let avail = true;\n // @ts-expect-error items must not be empty\n return items.reduce(function (left, right) {\n let canBeInserted = t.isLiteral(right);\n\n if (!canBeInserted && avail) {\n canBeInserted = true;\n avail = false;\n }\n if (canBeInserted && t.isCallExpression(left)) {\n left.arguments.push(right);\n return left;\n }\n return t.callExpression(\n t.memberExpression(left, t.identifier(\"concat\")),\n [right],\n );\n });\n }\n\n return {\n name: \"transform-template-literals\",\n\n visitor: {\n TaggedTemplateExpression(path) {\n const { node } = path;\n const { quasi } = node;\n\n const strings = [];\n const raws = [];\n\n // Flag variable to check if contents of strings and raw are equal\n let isStringsRawEqual = true;\n\n for (const elem of quasi.quasis) {\n const { raw, cooked } = elem.value;\n const value =\n cooked == null\n ? path.scope.buildUndefinedNode()\n : t.stringLiteral(cooked);\n\n strings.push(value);\n raws.push(t.stringLiteral(raw));\n\n if (raw !== cooked) {\n // false even if one of raw and cooked are not equal\n isStringsRawEqual = false;\n }\n }\n\n const helperArgs = [t.arrayExpression(strings)];\n // only add raw arrayExpression if there is any difference between raws and strings\n if (!isStringsRawEqual) {\n helperArgs.push(t.arrayExpression(raws));\n }\n\n const tmp = path.scope.generateUidIdentifier(\"templateObject\");\n path.scope.getProgramParent().push({ id: t.cloneNode(tmp) });\n\n path.replaceWith(\n t.callExpression(node.tag, [\n template.expression.ast`\n ${t.cloneNode(tmp)} || (\n ${tmp} = ${this.addHelper(helperName)}(${helperArgs})\n )\n `,\n // @ts-expect-error Fixme: quasi.expressions may contain TSAnyKeyword\n ...quasi.expressions,\n ]),\n );\n },\n\n TemplateLiteral(path) {\n // Skip TemplateLiteral in TSLiteralType\n if (path.parent.type === \"TSLiteralType\") {\n return;\n }\n const nodes: t.Expression[] = [];\n const expressions = path.get(\"expressions\") as NodePath<t.Expression>[];\n\n let index = 0;\n for (const elem of path.node.quasis) {\n if (elem.value.cooked) {\n nodes.push(t.stringLiteral(elem.value.cooked));\n }\n\n if (index < expressions.length) {\n const expr = expressions[index++];\n const node = expr.node;\n if (!t.isStringLiteral(node, { value: \"\" })) {\n nodes.push(node);\n }\n }\n }\n\n // since `+` is left-to-right associative\n // ensure the first node is a string if first/second isn't\n if (\n !t.isStringLiteral(nodes[0]) &&\n !(ignoreToPrimitiveHint && t.isStringLiteral(nodes[1]))\n ) {\n nodes.unshift(t.stringLiteral(\"\"));\n }\n let root = nodes[0];\n\n if (ignoreToPrimitiveHint) {\n for (let i = 1; i < nodes.length; i++) {\n root = t.binaryExpression(\"+\", root, nodes[i]);\n }\n } else if (nodes.length > 1) {\n root = buildConcatCallExpressions(nodes);\n }\n\n path.replaceWith(root);\n },\n },\n };\n});\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAAmD,IAAAE,QAAA,GAOpC,IAAAC,0BAAO,EAAC,CAACC,GAAG,EAAEC,OAAgB,KAAK;EAAA,IAAAC,eAAA,EAAA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EA,CAAC,GAAGR,KAAK,CAACG,MAAM,EAAEK,CAAC,EAAE,EAAE;YACrCD,IAAI,GAAGjD,WAAC,CAACmD,gBAAgB,CAAC,GAAG,EAAEF,IAAI,EAAEP,KAAK,CAACQ,CAAC,CAAC,CAAC;UAChD;QACF,CAAC,MAAM,IAAIR,KAAK,CAACG,MAAM,GAAG,CAAC,EAAE;UAC3BI,IAAI,GAAGxD,0BAA0B,CAACiD,KAAK,CAAC;QAC1C;QAEA/B,IAAI,CAACqB,WAAW,CAACiB,IAAI,CAAC;MACxB;IACF;EACF,CAAC;AACH,CAAC,CAAC;AAAAG,OAAA,CAAAC,OAAA,GAAAxE,QAAA"}
\ No newline at end of file diff --git a/node_modules/@babel/plugin-transform-template-literals/package.json b/node_modules/@babel/plugin-transform-template-literals/package.json new file mode 100644 index 00000000..c4b9ad1a --- /dev/null +++ b/node_modules/@babel/plugin-transform-template-literals/package.json @@ -0,0 +1,34 @@ +{ + "name": "@babel/plugin-transform-template-literals", + "version": "7.22.5", + "description": "Compile ES2015 template literals to ES5", + "repository": { + "type": "git", + "url": "https://github.com/babel/babel.git", + "directory": "packages/babel-plugin-transform-template-literals" + }, + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "main": "./lib/index.js", + "dependencies": { + "@babel/helper-plugin-utils": "^7.22.5" + }, + "keywords": [ + "babel-plugin" + ], + "peerDependencies": { + "@babel/core": "^7.0.0-0" + }, + "devDependencies": { + "@babel/core": "^7.22.5", + "@babel/helper-plugin-test-runner": "^7.22.5" + }, + "homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-template-literals", + "engines": { + "node": ">=6.9.0" + }, + "author": "The Babel Team (https://babel.dev/team)", + "type": "commonjs" +}
\ No newline at end of file |
