diff --git a/tools/mujs/lib/compiler/transform.ts b/tools/mujs/lib/compiler/transform.ts index ccaada8bd..15fca0483 100644 --- a/tools/mujs/lib/compiler/transform.ts +++ b/tools/mujs/lib/compiler/transform.ts @@ -1042,14 +1042,17 @@ export class Transformer { private makeVariableInitializer(decl: VariableDeclaration): ast.Statement { contract.requires(!!decl.initializer, "decl", "Expected variable declaration to have an initializer"); - return this.withLocation(decl.node, { - kind: ast.binaryOperatorExpressionKind, - left: { - kind: ast.loadLocationExpressionKind, - name: decl.variable.name, - }, - operator: "=", - right: decl.initializer, + return this.withLocation(decl.node, { + kind: ast.expressionStatementKind, + expression: this.withLocation(decl.node, { + kind: ast.binaryOperatorExpressionKind, + left: { + kind: ast.loadLocationExpressionKind, + name: decl.variable.name, + }, + operator: "=", + right: decl.initializer, + }), }); } diff --git a/tools/mujs/tests/output/modules/export/Mu.out.json b/tools/mujs/tests/output/modules/export/Mu.out.json index 14538cb04..da6c16797 100644 --- a/tools/mujs/tests/output/modules/export/Mu.out.json +++ b/tools/mujs/tests/output/modules/export/Mu.out.json @@ -103,39 +103,53 @@ "kind": "Block", "statements": [ { - "kind": "BinaryOperatorExpression", - "left": { - "kind": "LoadLocationExpression", - "name": { - "kind": "Identifier", - "ident": "w", + "kind": "ExpressionStatement", + "expression": { + "kind": "BinaryOperatorExpression", + "left": { + "kind": "LoadLocationExpression", + "name": { + "kind": "Identifier", + "ident": "w", + "loc": { + "file": "other.ts", + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + "operator": "=", + "right": { + "kind": "NumberLiteral", + "raw": "42", + "value": 42, "loc": { "file": "other.ts", "start": { "line": 3, - "column": 11 + "column": 15 }, "end": { "line": 3, - "column": 12 + "column": 17 } } - } - }, - "operator": "=", - "right": { - "kind": "NumberLiteral", - "raw": "42", - "value": 42, + }, "loc": { "file": "other.ts", "start": { "line": 3, - "column": 15 + "column": 0 }, "end": { "line": 3, - "column": 17 + "column": 18 } } }, @@ -288,39 +302,53 @@ "kind": "Block", "statements": [ { - "kind": "BinaryOperatorExpression", - "left": { - "kind": "LoadLocationExpression", - "name": { - "kind": "Identifier", - "ident": "v", + "kind": "ExpressionStatement", + "expression": { + "kind": "BinaryOperatorExpression", + "left": { + "kind": "LoadLocationExpression", + "name": { + "kind": "Identifier", + "ident": "v", + "loc": { + "file": "index.ts", + "start": { + "line": 8, + "column": 4 + }, + "end": { + "line": 8, + "column": 5 + } + } + } + }, + "operator": "=", + "right": { + "kind": "NumberLiteral", + "raw": "42", + "value": 42, "loc": { "file": "index.ts", "start": { "line": 8, - "column": 4 + "column": 8 }, "end": { "line": 8, - "column": 5 + "column": 10 } } - } - }, - "operator": "=", - "right": { - "kind": "NumberLiteral", - "raw": "42", - "value": 42, + }, "loc": { "file": "index.ts", "start": { "line": 8, - "column": 8 + "column": 0 }, "end": { "line": 8, - "column": 10 + "column": 11 } } }, diff --git a/tools/mujs/tests/output/modules/reexport/Mu.out.json b/tools/mujs/tests/output/modules/reexport/Mu.out.json index 76604d439..ee11c7976 100644 --- a/tools/mujs/tests/output/modules/reexport/Mu.out.json +++ b/tools/mujs/tests/output/modules/reexport/Mu.out.json @@ -103,39 +103,53 @@ "kind": "Block", "statements": [ { - "kind": "BinaryOperatorExpression", - "left": { - "kind": "LoadLocationExpression", - "name": { - "kind": "Identifier", - "ident": "v", + "kind": "ExpressionStatement", + "expression": { + "kind": "BinaryOperatorExpression", + "left": { + "kind": "LoadLocationExpression", + "name": { + "kind": "Identifier", + "ident": "v", + "loc": { + "file": "other.ts", + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + "operator": "=", + "right": { + "kind": "NumberLiteral", + "raw": "42", + "value": 42, "loc": { "file": "other.ts", "start": { "line": 3, - "column": 11 + "column": 15 }, "end": { "line": 3, - "column": 12 + "column": 17 } } - } - }, - "operator": "=", - "right": { - "kind": "NumberLiteral", - "raw": "42", - "value": 42, + }, "loc": { "file": "other.ts", "start": { "line": 3, - "column": 15 + "column": 0 }, "end": { "line": 3, - "column": 17 + "column": 18 } } }, diff --git a/tools/mujs/tests/output/modules/reexport_all/Mu.out.json b/tools/mujs/tests/output/modules/reexport_all/Mu.out.json index f0d8e4d13..3aa3bb8d2 100644 --- a/tools/mujs/tests/output/modules/reexport_all/Mu.out.json +++ b/tools/mujs/tests/output/modules/reexport_all/Mu.out.json @@ -103,39 +103,53 @@ "kind": "Block", "statements": [ { - "kind": "BinaryOperatorExpression", - "left": { - "kind": "LoadLocationExpression", - "name": { - "kind": "Identifier", - "ident": "v", + "kind": "ExpressionStatement", + "expression": { + "kind": "BinaryOperatorExpression", + "left": { + "kind": "LoadLocationExpression", + "name": { + "kind": "Identifier", + "ident": "v", + "loc": { + "file": "other.ts", + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + "operator": "=", + "right": { + "kind": "NumberLiteral", + "raw": "42", + "value": 42, "loc": { "file": "other.ts", "start": { "line": 3, - "column": 11 + "column": 15 }, "end": { "line": 3, - "column": 12 + "column": 17 } } - } - }, - "operator": "=", - "right": { - "kind": "NumberLiteral", - "raw": "42", - "value": 42, + }, "loc": { "file": "other.ts", "start": { "line": 3, - "column": 15 + "column": 0 }, "end": { "line": 3, - "column": 17 + "column": 18 } } }, diff --git a/tools/mujs/tests/output/modules/reexport_rename/Mu.out.json b/tools/mujs/tests/output/modules/reexport_rename/Mu.out.json index 1a24422f9..dfb15def0 100644 --- a/tools/mujs/tests/output/modules/reexport_rename/Mu.out.json +++ b/tools/mujs/tests/output/modules/reexport_rename/Mu.out.json @@ -103,39 +103,53 @@ "kind": "Block", "statements": [ { - "kind": "BinaryOperatorExpression", - "left": { - "kind": "LoadLocationExpression", - "name": { - "kind": "Identifier", - "ident": "v", + "kind": "ExpressionStatement", + "expression": { + "kind": "BinaryOperatorExpression", + "left": { + "kind": "LoadLocationExpression", + "name": { + "kind": "Identifier", + "ident": "v", + "loc": { + "file": "other.ts", + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + } + }, + "operator": "=", + "right": { + "kind": "NumberLiteral", + "raw": "42", + "value": 42, "loc": { "file": "other.ts", "start": { "line": 3, - "column": 11 + "column": 15 }, "end": { "line": 3, - "column": 12 + "column": 17 } } - } - }, - "operator": "=", - "right": { - "kind": "NumberLiteral", - "raw": "42", - "value": 42, + }, "loc": { "file": "other.ts", "start": { "line": 3, - "column": 15 + "column": 0 }, "end": { "line": 3, - "column": 17 + "column": 18 } } }, diff --git a/tools/mujs/tests/output/modules/var_1/Mu.out.json b/tools/mujs/tests/output/modules/var_1/Mu.out.json index d00392ca9..98dcbd5fc 100644 --- a/tools/mujs/tests/output/modules/var_1/Mu.out.json +++ b/tools/mujs/tests/output/modules/var_1/Mu.out.json @@ -39,39 +39,53 @@ "kind": "Block", "statements": [ { - "kind": "BinaryOperatorExpression", - "left": { - "kind": "LoadLocationExpression", - "name": { - "kind": "Identifier", - "ident": "x", + "kind": "ExpressionStatement", + "expression": { + "kind": "BinaryOperatorExpression", + "left": { + "kind": "LoadLocationExpression", + "name": { + "kind": "Identifier", + "ident": "x", + "loc": { + "file": "index.ts", + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + } + } + }, + "operator": "=", + "right": { + "kind": "NumberLiteral", + "raw": "42", + "value": 42, "loc": { "file": "index.ts", "start": { "line": 1, - "column": 4 + "column": 8 }, "end": { "line": 1, - "column": 5 + "column": 10 } } - } - }, - "operator": "=", - "right": { - "kind": "NumberLiteral", - "raw": "42", - "value": 42, + }, "loc": { "file": "index.ts", "start": { "line": 1, - "column": 8 + "column": 0 }, "end": { "line": 1, - "column": 10 + "column": 11 } } }, diff --git a/tools/mujs/tests/output/modules/var_exp_1/Mu.out.json b/tools/mujs/tests/output/modules/var_exp_1/Mu.out.json index 1ae0357bd..0af546385 100644 --- a/tools/mujs/tests/output/modules/var_exp_1/Mu.out.json +++ b/tools/mujs/tests/output/modules/var_exp_1/Mu.out.json @@ -39,39 +39,53 @@ "kind": "Block", "statements": [ { - "kind": "BinaryOperatorExpression", - "left": { - "kind": "LoadLocationExpression", - "name": { - "kind": "Identifier", - "ident": "x", + "kind": "ExpressionStatement", + "expression": { + "kind": "BinaryOperatorExpression", + "left": { + "kind": "LoadLocationExpression", + "name": { + "kind": "Identifier", + "ident": "x", + "loc": { + "file": "index.ts", + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + } + }, + "operator": "=", + "right": { + "kind": "NumberLiteral", + "raw": "42", + "value": 42, "loc": { "file": "index.ts", "start": { "line": 1, - "column": 11 + "column": 15 }, "end": { "line": 1, - "column": 12 + "column": 17 } } - } - }, - "operator": "=", - "right": { - "kind": "NumberLiteral", - "raw": "42", - "value": 42, + }, "loc": { "file": "index.ts", "start": { "line": 1, - "column": 15 + "column": 0 }, "end": { "line": 1, - "column": 17 + "column": 18 } } },