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

isEnumerateCallExpression sometimes returns false when it should return true #25

Closed
davidmurdoch opened this issue Jan 12, 2021 · 1 comment

Comments

@davidmurdoch
Copy link

I have a complex monorepo using uncompiled typescript via ts-node and ttypescript.

I've found that within the function isEnumerateCallExpression declaration.getSourceFile().fileName === indexTs may evaluate to false when it should be true.

A potential fix for this is to copy the isOurStubModule function from ts-transformer-inline-file and use it, instead, like this:

const stubModuleSource = fs.readFileSync(path.join(__dirname, 'index.d.ts'), 'utf8');
function isOurStubModule(sourceFile) {
    // Comparing of the file names may not be reliable, it doesn't work e.g. with
    // yarn's "link" resolution used in this module's end-to-end tests.
    return sourceFile.text === stubModuleSource;
}
function isEnumerateCallExpression(node, typeChecker) {
    if (!ts.isCallExpression(node)) {
        return false;
    }
    var signature = typeChecker.getResolvedSignature(node);
    if (typeof signature === 'undefined') {
        return false;
    }
    var declaration = signature.declaration;
    return !!declaration
        && isOurStubModule(declaration.getSourceFile()) // <----- HERE -----
        && !!declaration.name
        && declaration.name.getText() === 'enumerate';
}

(sorry about the JavaScript snippet, I was hacking on directly within my node_modules)

kimamula added a commit that referenced this issue Jan 18, 2021
@kimamula
Copy link
Owner

kimamula commented Jan 18, 2021

There was a similar problem in ts-transformer-keys, which has been already resolved.
I fixed ts-transformer-enumerate in the same way and released v0.5.2. Please give it a try and see if the issue is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants