Skip to content

Commit

Permalink
Take the module from the parent to avoid a constructor argument
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Apr 16, 2018
1 parent 4978d7c commit a903b28
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 21 deletions.
8 changes: 7 additions & 1 deletion src/Module.ts
Expand Up @@ -220,7 +220,13 @@ export default class Module {

timeStart('analyse ast', 3);

this.ast = new Program(this.esTreeAst, nodeConstructors, {}, this, this.scope, false);
this.ast = new Program(
this.esTreeAst,
nodeConstructors,
{ type: 'Module', module: this },
this.scope,
false
);

timeEnd('analyse ast', 3);
}
Expand Down
1 change: 0 additions & 1 deletion src/ast/nodes/ArrowFunctionExpression.ts
Expand Up @@ -72,7 +72,6 @@ export default class ArrowFunctionExpression extends NodeBase {
esTreeNode.body,
nodeConstructors,
this,
this.module,
new Scope({ parent: this.scope }),
true
);
Expand Down
1 change: 0 additions & 1 deletion src/ast/nodes/CatchClause.ts
Expand Up @@ -25,7 +25,6 @@ export default class CatchClause extends NodeBase {
esTreeNode.body,
nodeConstructors,
this,
this.module,
this.scope,
true
);
Expand Down
1 change: 0 additions & 1 deletion src/ast/nodes/ClassDeclaration.ts
Expand Up @@ -27,7 +27,6 @@ export default class ClassDeclaration extends ClassNode {
esTreeNode.id,
nodeConstructors,
this,
this.module,
<Scope>this.scope.parent,
false
);
Expand Down
1 change: 0 additions & 1 deletion src/ast/nodes/FunctionDeclaration.ts
Expand Up @@ -23,7 +23,6 @@ export default class FunctionDeclaration extends FunctionNode {
esTreeNode.id,
nodeConstructors,
this,
this.module,
this.scope.parent,
false
);
Expand Down
1 change: 0 additions & 1 deletion src/ast/nodes/shared/FunctionNode.ts
Expand Up @@ -93,7 +93,6 @@ export default class FunctionNode extends NodeBase {
esTreeNode.body,
nodeConstructors,
this,
this.module,
new Scope({ parent: this.scope }),
true
);
Expand Down
21 changes: 6 additions & 15 deletions src/ast/nodes/shared/Node.ts
Expand Up @@ -85,7 +85,7 @@ export class NodeBase implements ExpressionNode {
start: number;
end: number;
module: Module;
parent: Node | { type?: string };
parent: Node | { type: string; module: Module };

// Not initialised during construction
included: boolean = false;
Expand All @@ -94,19 +94,18 @@ export class NodeBase implements ExpressionNode {
esTreeNode: GenericEsTreeNode,
// we need to pass down the node constructors to avoid a circular dependency
nodeConstructors: { [p: string]: typeof NodeBase },
parent: Node | {},
module: Module,
parent: Node | { type: string; module: Module },
parentScope: Scope,
preventNewScope: boolean
) {
this.keys = keys[esTreeNode.type] || getAndCreateKeys(esTreeNode);
this.parent = parent;
this.module = module;
this.module = parent.module;
this.createScope(parentScope, preventNewScope);
this.parseNode(esTreeNode, nodeConstructors);
this.initialise();
module.magicString.addSourcemapLocation(this.start);
module.magicString.addSourcemapLocation(this.end);
this.module.magicString.addSourcemapLocation(this.start);
this.module.magicString.addSourcemapLocation(this.end);
}

/**
Expand Down Expand Up @@ -249,22 +248,14 @@ export class NodeBase implements ExpressionNode {
child,
nodeConstructors,
this,
this.module,
this.scope,
false
)
);
}
} else {
(<GenericEsTreeNode>this)[key] = new (nodeConstructors[value.type] ||
nodeConstructors.UnknownNode)(
value,
nodeConstructors,
this,
this.module,
this.scope,
false
);
nodeConstructors.UnknownNode)(value, nodeConstructors, this, this.scope, false);
}
}
}
Expand Down

0 comments on commit a903b28

Please sign in to comment.