Skip to content
This repository was archived by the owner on Oct 5, 2021. It is now read-only.
This repository was archived by the owner on Oct 5, 2021. It is now read-only.

Fails typescript parsing when having nested arrow functions #75

Closed
@Nysosis

Description

@Nysosis

Versions:

  • typewiz-node: 1.1.0
  • typescript: 2.9.2
  • ts-node: 5.0.1
  • node 8.11.3 (and 8.9.0)

This is a stripped down version of some code I have that causes the error

// ~/src/app.ts
async function Main () {
    await Promise.resolve([
        1, 2, 3
    ]).then((results) => {
        if (results.length > 0) {
            results.forEach((result) => console.log(result));
            process.exit(1);
        }
    });
}

Main();

However I've managed to strip it back even further (to eliminate it being something related to async) to the below. If I remove the results.forEach… and instead just do console.log(results) then typewiz works fine. So I think it due to having the nested arrow statements somehow?

// ~/src/app.ts
function doTheThing(cb) {
    cb([1,2,3]);
}

doTheThing((results) => {
    results.forEach((result) => console.log(result));
});

On running: typewiz-node src/app.ts

Error:

[PROJECT_ROOT]\node_modules\typescript\lib\typescript.js:8984
        return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
                                                                       ^
TypeError: Cannot read property 'text' of undefined
    at Object.getTokenPosOfNode ([PROJECT_ROOT]\node_modules\typescript\lib\typescript.js:8984:72)
    at NodeObject.getStart ([PROJECT_ROOT]\node_modules\typescript\lib\typescript.js:106669:23)
    at hasParensAroundArguments ([PROJECT_ROOT]\node_modules\typewiz-core\src\transformer.ts:67:13)
    at visitor ([PROJECT_ROOT]\node_modules\typewiz-core\src\transformer.ts:169:21)
    at visitNodes ([PROJECT_ROOT]\node_modules\typescript\lib\typescript.js:56887:48)
    at Object.visitEachChild ([PROJECT_ROOT]\node_modules\typescript\lib\typescript.js:57052:156)
    at visitor ([PROJECT_ROOT]\node_modules\typewiz-core\src\transformer.ts:143:10)
    at visitNode ([PROJECT_ROOT]\node_modules\typescript\lib\typescript.js:56836:23)
    at Object.visitEachChild ([PROJECT_ROOT]\node_modules\typescript\lib\typescript.js:57106:49)
    at visitor ([PROJECT_ROOT]\node_modules\typewiz-core\src\transformer.ts:143:10)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions