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

Node#getText() will throw if node was made with another transformer #24273

Closed
mohsen1 opened this issue May 19, 2018 · 6 comments
Closed

Node#getText() will throw if node was made with another transformer #24273

mohsen1 opened this issue May 19, 2018 · 6 comments
Assignees
Labels
Question An issue which isn't directly actionable in code

Comments

@mohsen1
Copy link
Contributor

mohsen1 commented May 19, 2018

When a transformers adds a new node to the AST, reading that node text will throw an error because sourceFile is not reflecting the newly added node
TypeScript Version: 2.9.0

Search Terms:
Transformers, AST, getText()

Code
reproduction repo

See Travis Logs and comments in index.ts

Expected behavior:
No Error
Actual behavior:

Error

home/travis/build/mohsen1/ts-transformer-bug/node_modules/typescript/lib/typescript.js:102266
            ts.Debug.assert(!ts.positionIsSynthesized(this.pos) && !ts.positionIsSynthesized(this.end), message || "Node must have a real position for this operation");
@mohsen1 mohsen1 changed the title Node#getText() will throw if node was made with a tranformer Node#getText() will throw if node was made with another transformer May 20, 2018
@RyanCavanaugh
Copy link
Member

Have you tried calling getTextOfNode instead?

@mohsen1
Copy link
Contributor Author

mohsen1 commented May 22, 2018

I don't see getTextOfNode exported in typescript.d.ts.

mohsen1/ts-transformer-bug#1

@mohsen1
Copy link
Contributor Author

mohsen1 commented May 29, 2018

@RyanCavanaugh Can you take a look?

@RyanCavanaugh RyanCavanaugh self-assigned this May 29, 2018
@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label May 29, 2018
@RyanCavanaugh
Copy link
Member

@mohsen1 this call stack doesn't look related to what you were describing?

tsc
node dist/index.js

C:\Throwaway\ts-transformer-bug\node_modules\typescript\lib\typescript.js:13089
        return node.kind === 272 /* SourceFile */;
                    ^

TypeError: Cannot read property 'kind' of undefined
    at Object.isSourceFile (C:\Throwaway\ts-transformer-bug\node_modules\typescript\lib\typescript.js:13089:21)
    at Object.printNode (C:\Throwaway\ts-transformer-bug\node_modules\typescript\lib\typescript.js:72638:40)
    at compile (C:\Throwaway\ts-transformer-bug\dist\index.js:28:27)
    at Object.<anonymous> (C:\Throwaway\ts-transformer-bug\dist\index.js:53:1)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)
    at Module.load (module.js:561:32)
    at tryModuleLoad (module.js:501:12)
    at Function.Module._load (module.js:493:3)

@mohsen1
Copy link
Contributor Author

mohsen1 commented Jun 9, 2018

@RyanCavanaugh Not sure how you got Cannot read property 'kind' of undefined Please run yarn test or npm test .

I'm still not able to read text of a synthetically added node.

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants