Skip to content

Commit

Permalink
Fix TaggedTemplate evaluation bug
Browse files Browse the repository at this point in the history
This line of code causes a type error since `TaggedTemplateLiteral`s do not have a property called "expressions".

This change does what is probably expected. However, to maintain the existing behaviour, the line should instead be:

```js
const exprs: Array<undefined | NodePath<t.Node>> = path.isTemplateLiteral()
    ? path.get('expressions')
    : []
```
  • Loading branch information
nmn authored and nicolo-ribaudo committed Jan 2, 2023
1 parent 7d20fdf commit a143a20
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/babel-traverse/src/path/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,11 @@ function evaluateQuasis(
let str = "";

let i = 0;
const exprs = path.get("expressions");
const exprs: Array<NodePath<t.Node>> = path.isTemplateLiteral()
? path.get('expressions')
: (path as NodePath<t.TaggedTemplateExpression>)
.get('quasi')
.get('expressions');

for (const elem of quasis) {
// not confident, evaluated an expression we don't like
Expand Down

0 comments on commit a143a20

Please sign in to comment.