Skip to content

Initial Transformer Setup#279

Merged
lolleko merged 4 commits intomultiphase-transpilefrom
initial-transformer
Nov 22, 2018
Merged

Initial Transformer Setup#279
lolleko merged 4 commits intomultiphase-transpilefrom
initial-transformer

Conversation

@lolleko
Copy link
Copy Markdown
Member

@lolleko lolleko commented Nov 10, 2018

Added Transformer setup that allows us to incrementally port our transpile functions to transform functions.

We have to port all transpile functions that transpile Nodes that are not allowed in the 2nd AST.

Once that's done we should restructure the whole project, because right now the transformation process is just hacked before the transpilation.

Added Transformer setup that allows us to incrementally port our transpile functions to transform functions.

We have to prot all transpile functions that transpile Nodes that are not allowed in the 2nd AST.

Once thats done we should restrucutre the whole project, because right now the transform process is just hacked before the transpilation.
return ts
.transform(node,
[(ctx: ts.TransformationContext) => {
this.context = ctx;
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.

Might be nicer to maybe put this in a static function, then create an instance of the transformer here with context as constructor argument.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agreed, we should replicate the pattern we use for transpiler targets (TranspilerFactory, createTranspiler...). Since we most likely want to have differentiations transformers for differentiations Lua versions in the future. But I would reorganise that some point later once we are sure how exactly the transformer architecture will be implemented.

private context: ts.TransformationContext;

constructor(checker: ts.TypeChecker, options: CompilerOptions) {
this.checker = checker;
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.

constructor(
    private checker: ts.TypeChecker,
    private context: ts.TransformationContext,
    private options: CompilerOptions
) { }

Is slightly nicer imo

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this is only nicer if all members are declared & initialized in the constructor, which is not the case here.

switch (node.kind) {
// Declarations
case ts.SyntaxKind.ImportDeclaration:
return this.visitImportDeclaration(node as ts.ImportDeclaration);
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.

Random idea: Maybe we should have default this.ignoreNode(node) (returns undefined) and this.visitDefault(node) (returns node)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ideally all those method stubs should contain an actual implementation in the future. If we figure out that we don't need to transform a node (ignore it) we can just delete the case from the switch statement.

}

@Test("Import named bindings exception")
public namedBindigsException(): void {
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.

Maybe ignore this for now instead of removing, since we probably want to still have this test on the transformer instead of transpiler.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This test was using a custom created AST/Node I don't think that named bindings exception can ever be thrown.

@lolleko lolleko added this to the 1.0.0 milestone Nov 11, 2018
project:
default:
target: 90
target: 80
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.

MonkaS

@lolleko lolleko merged commit e124f1d into multiphase-transpile Nov 22, 2018
@lolleko lolleko deleted the initial-transformer branch December 2, 2018 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants