Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip template literal transform for TSLiteralType #14582

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/babel-plugin-transform-template-literals/src/index.ts
@@ -1,5 +1,6 @@
import { declare } from "@babel/helper-plugin-utils";
import { template, types as t } from "@babel/core";
import type { NodePath } from "@babel/traverse";

export interface Options {
loose?: boolean;
Expand Down Expand Up @@ -31,8 +32,9 @@ export default declare((api, options: Options) => {
* the second member and convert that one, which reflects the spec behavior
* of template literals.
*/
function buildConcatCallExpressions(items) {
function buildConcatCallExpressions(items: t.Expression[]): t.CallExpression {
let avail = true;
// @ts-expect-error items must not be empty
return items.reduce(function (left, right) {
let canBeInserted = t.isLiteral(right);

Expand Down Expand Up @@ -104,8 +106,12 @@ export default declare((api, options: Options) => {
},

TemplateLiteral(path) {
const nodes = [];
const expressions = path.get("expressions");
// Skip TemplateLiteral in TSLiteralType
if (path.parent.type === "TSLiteralType") {
return;
}
const nodes: t.Expression[] = [];
const expressions = path.get("expressions") as NodePath<t.Expression>[];

let index = 0;
for (const elem of path.node.quasis) {
Expand Down
@@ -0,0 +1,2 @@
type World = "world";
type Greeting = `hello ${World}`;
@@ -0,0 +1,3 @@
{
"plugins": ["transform-template-literals", "syntax-typescript"]
}
@@ -0,0 +1,2 @@
type World = "world";
type Greeting = `hello ${World}`;