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: handle static eval for sequence expression (fix TS 4.4+) #289

Merged
merged 1 commit into from
May 23, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
]