Skip to content

QuestionDotToken being stripped out? #5

Closed

Description

@johnjenkins

Hi there - Thanks for your hard work on this - it's a lifesaver!
One potential snag I've run into is: on clone, QuestionDotTokens are stripped out meaning optional chaining doesn't work in the final, compiled code.

Example:

// original node
this.person?.hasEMailAddress?.emailAddress

...
// during transform
import { cloneNode } from "ts-clone-node";
...
cloneNode(node, { typescript: ts });
...

Cloned node:

this.person.hasEMailAddress.emailAddress

If you could take a look into this or point me in a direction, I'd be most obliged!

Activity

  1. johnjenkins commented on Jun 9, 2021

    @johnjenkins
    Author

    I think you'll need a new clonePropertyAccessChain method?

    import {TS} from "./type/ts";
    import {CloneNodeVisitorOptions} from "./clone-node-options";
    
    export function clonePropertyAccessChain(node: TS.PropertyAccessChain, options: CloneNodeVisitorOptions<TS.PropertyAccessChain>): TS.PropertyAccessChain {
    	return options.factory.createPropertyAccessChain(
    		options.hook("expression", options.nextNode(node.expression), node.expression),
                    options.hook("questionDotToken", options.nextNode(node.questionDotToken),
    		options.hook("name", options.nextNode(node.name), node.name)
    	);
    }
    

    well, something like that anyway :D

  2. wessberg commented on Jun 11, 2021

    @wessberg
    Owner

    Hey there. Nice catch. It has been fixed in v0.3.24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions