Skip to content

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

Closed

Description

@mohsen1

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");

Activity

  1. 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[/+] on May 20, 2018
  2. RyanCavanaugh commented on May 21, 2018

    @RyanCavanaugh
    Member

    Have you tried calling getTextOfNode instead?

  3. mohsen1 commented on May 22, 2018

    @mohsen1
    ContributorAuthor

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

    mohsen1/ts-transformer-bug#1

  4. mohsen1 commented on May 29, 2018

    @mohsen1
    ContributorAuthor

    Ryan Cavanaugh (@RyanCavanaugh) Can you take a look?

  5. RyanCavanaugh commented on May 29, 2018

    @RyanCavanaugh
    Member

    Mohsen Azimi (@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)
    
  6. mohsen1 commented on Jun 9, 2018

    @mohsen1
    ContributorAuthor

    Ryan Cavanaugh (@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.

  7. typescript-bot commented on Jul 13, 2019

    @typescript-bot
    Contributor

    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.

  8. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

QuestionAn issue which isn't directly actionable in code

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions