Skip to content

Commit

Permalink
fix: handle static eval for sequence expression (fix TS 4.4+) (#289)
Browse files Browse the repository at this point in the history
- Fixes #288
  • Loading branch information
styfle authored May 23, 2022
1 parent fd36510 commit 60c5f2a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/utils/static-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ const visitors: Record<string, (this: State, node: Node, walk: Walk) => Promise<
}
return { value: obj };
},
'SequenceExpression': async function SequenceExpression(this: State, node: Node, walk: Walk) {
if ('expressions' in node && node.expressions.length === 2 && node.expressions[0].type === 'Literal' && node.expressions[0].value === 0 && node.expressions[1].type === 'MemberExpression') {
const arg = await walk(node.expressions[1]);
return arg;
}
return undefined;
},
'TemplateLiteral': async function TemplateLiteral(this: State, node: Node, walk: Walk) {
let val: StaticValue | ConditionalValue = { value: '' };
for (var i = 0; i < node.expressions.length; i++) {
Expand Down
1 change: 1 addition & 0 deletions test/unit/ts-path-join/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
file content
7 changes: 7 additions & 0 deletions test/unit/ts-path-join/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
// See https://devblogs.microsoft.com/typescript/announcing-typescript-4-4/#more-compliant-indirect-calls-for-imported-functions
// Also https://2ality.com/2015/12/references.html
const file = (0, path_1.join)(__dirname, 'file.txt');
console.log(file);
5 changes: 5 additions & 0 deletions test/unit/ts-path-join/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[
"package.json",
"test/unit/ts-path-join/file.txt",
"test/unit/ts-path-join/input.js"
]

0 comments on commit 60c5f2a

Please sign in to comment.