Skip to content

Is replaceCurrentNodeBy: correct (When include a file in another, the included elements have parent nil) #965

@Ducasse

Description

@Ducasse

I have the impression that

replaceCurrentNodeBy: newNodes
	"When we do a transformation I replace the current node by its transformation."

	replacement pop.
	replacement push: newNodes

should be written as

replaceCurrentNodeBy: newNodes
	"When we do a transformation I replace the current node by its transformation."

        | replaced |
	replacedParent := replacement pop.
        newNodes do: [ :each | each basicParent: replacedParent ].
	replacement push: newNodes

Imagine we have

Root 
   Element
   inputFile

with inputFile

RootOfFile1 
   Header1 

where tab expressed parent reference

after include

We get

Root 
   Element
RootOfFile1

RootOfFIle1 should be Root

This is a problem because it means that we can lose the way to resolve references using fromFile which is shared in top element.

Should

  • write a couple test to verify this hypothesis.
  • Tests could be at the level of the replaceCurrentNodeBy:
  • Tests could be at the level of the MicFileIncluder
ast := Microdown parseFile: '/Users/ducasse/Workspace/FirstCircle/MyBooks/Bk-Writing/PharoBooks2/BuildingApplicationWithSpec2/index.md' asFileReference.

MicFileIncluder new topFile: '/Users/ducasse/Workspace/FirstCircle/MyBooks/Bk-Writing/PharoBooks2/BuildingApplicationWithSpec2/index.md' asFileReference;
	expandAllInputOf: ast.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions