Skip to content

Commit e6c6ecf

Browse files
authored
Merge pull request #4 from ConsenSys/factory-and-tuple-fixes
Fixes for ASTNodeFactory and TupleExpression
2 parents a1aaf05 + 8572a24 commit e6c6ecf

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/ast/ast_node_factory.ts

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ const argExtractionMapping = new Map<ASTNodeConstructor<ASTNode>, (node: any) =>
320320
(node: TupleExpression): Specific<ConstructorParameters<typeof TupleExpression>> => [
321321
node.typeString,
322322
node.isInlineArray,
323-
node.vComponents,
323+
node.vOriginalComponents,
324324
node.raw
325325
]
326326
],
@@ -890,57 +890,68 @@ export class ASTNodeFactory {
890890
}
891891

892892
makeIdentifierFor(
893-
declaration:
893+
target:
894894
| VariableDeclaration
895895
| ContractDefinition
896896
| FunctionDefinition
897897
| StructDefinition
898898
| EventDefinition
899899
| EnumDefinition
900+
| ImportDirective
900901
): Identifier {
901902
let typeString: string;
902903

903-
if (declaration instanceof VariableDeclaration) {
904-
typeString = declaration.typeString;
905-
} else if (declaration instanceof FunctionDefinition) {
906-
const args = declaration.vParameters.vParameters.map(this.typeExtractor);
904+
if (target instanceof VariableDeclaration) {
905+
typeString = target.typeString;
906+
} else if (target instanceof FunctionDefinition) {
907+
const args = target.vParameters.vParameters.map(this.typeExtractor);
907908

908909
const result = [`function (${args.join(",")})`];
909910

910-
if (declaration.stateMutability !== FunctionStateMutability.NonPayable) {
911-
result.push(declaration.stateMutability);
911+
if (target.stateMutability !== FunctionStateMutability.NonPayable) {
912+
result.push(target.stateMutability);
912913
}
913914

914-
if (declaration.visibility !== FunctionVisibility.Public) {
915-
result.push(declaration.visibility);
915+
if (target.visibility !== FunctionVisibility.Public) {
916+
result.push(target.visibility);
916917
}
917918

918-
if (declaration.vReturnParameters.vParameters.length) {
919-
const rets = declaration.vReturnParameters.vParameters.map(this.typeExtractor);
919+
if (target.vReturnParameters.vParameters.length) {
920+
const rets = target.vReturnParameters.vParameters.map(this.typeExtractor);
920921

921922
result.push(`returns (${rets.join(",")})`);
922923
}
923924

924925
typeString = result.join(" ");
925-
} else if (declaration instanceof ContractDefinition) {
926-
typeString = `type(contract ${declaration.name})`;
927-
} else if (declaration instanceof EventDefinition) {
928-
const args = declaration.vParameters.vParameters.map(this.typeExtractor);
926+
} else if (target instanceof ContractDefinition) {
927+
typeString = `type(contract ${target.name})`;
928+
} else if (target instanceof EventDefinition) {
929+
const args = target.vParameters.vParameters.map(this.typeExtractor);
929930

930931
typeString = `function (${args.join(",")})`;
932+
} else if (target instanceof ImportDirective) {
933+
typeString = "<missing>";
934+
935+
if (target.unitAlias === "") {
936+
throw new Error('Target ImportDirective required to have valid "unitAlias"');
937+
}
931938
} else {
932939
const name =
933-
declaration.vScope instanceof ContractDefinition
934-
? declaration.vScope.name + "." + declaration.name
935-
: declaration.name;
940+
target.vScope instanceof ContractDefinition
941+
? target.vScope.name + "." + target.name
942+
: target.name;
936943

937944
typeString =
938-
declaration instanceof StructDefinition
945+
target instanceof StructDefinition
939946
? `type(struct ${name} storage pointer)`
940947
: `type(enum ${name})`;
941948
}
942949

943-
return this.makeIdentifier(typeString, declaration.name, declaration.id);
950+
return this.makeIdentifier(
951+
typeString,
952+
target instanceof ImportDirective ? target.unitAlias : target.name,
953+
target.id
954+
);
944955
}
945956

946957
makeUnfinalized<T extends ASTNode>(

src/ast/implementation/expression/tuple_expression.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class TupleExpression extends Expression {
4040
*
4141
* The `null` value is used to represent empty spots.
4242
*/
43-
get components(): Array<number | null> {
43+
get components(): ReadonlyArray<number | null> {
4444
const result: Array<number | null> = [];
4545

4646
for (const component of this.vOriginalComponents) {
@@ -53,7 +53,7 @@ export class TupleExpression extends Expression {
5353
/**
5454
* An array of non-`null` components
5555
*/
56-
get vComponents(): Expression[] {
56+
get vComponents(): readonly Expression[] {
5757
const result: Expression[] = [];
5858

5959
for (const component of this.vOriginalComponents) {

0 commit comments

Comments
 (0)