Skip to content

Commit

Permalink
fix: skip template literal transform for TSLiteralType (#14582)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed May 25, 2022
1 parent 62fd56f commit deb832b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
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}`;

0 comments on commit deb832b

Please sign in to comment.