Skip to content

Generic algorithm to create a shallow, memberwise clone of a node.#5726

Merged
rbuckton merged 3 commits into
masterfrom
cloneNode
Nov 20, 2015
Merged

Generic algorithm to create a shallow, memberwise clone of a node.#5726
rbuckton merged 3 commits into
masterfrom
cloneNode

Conversation

@rbuckton
Copy link
Copy Markdown
Contributor

Eventually will be needed for transformations.

Supports #5595.

Comment thread src/compiler/utilities.ts
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind is copied again in the for loop, right? I just want to make sure I'm reading the code correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I originally wrote the cloneNode function before @vladima modified the Node constructor, when kind was set on the prototype. I can probably drop isExcludedPropertyForClone in favor of clone.hasOwnProperty(key).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will copy over flags and parent now, won't it? Which is bad unless they are provided by the caller.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, flags and parent are set in the Node constructor. See line 808 of core.ts:

    function Node(kind: SyntaxKind, pos: number, end: number) {
        this.kind = kind;
        this.pos = pos;
        this.end = end;
        this.flags = NodeFlags.None;
        this.parent = undefined;
    }

And line 191 of services.ts:

        constructor(kind: SyntaxKind, pos: number, end: number) {
            this.kind = kind;
            this.pos = pos;
            this.end = end;
            this.flags = NodeFlags.None;
            this.parent = undefined;
        }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, sounds good.

@sandersn
Copy link
Copy Markdown
Member

Looks good to me.

rbuckton added a commit that referenced this pull request Nov 20, 2015
Generic algorithm to create a shallow, memberwise clone of a node.
@rbuckton rbuckton merged commit c94dcbd into master Nov 20, 2015
@rbuckton rbuckton deleted the cloneNode branch November 20, 2015 18:54
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants