diff --git a/escodegen.js b/escodegen.js index 3d864bbe..575cfe89 100644 --- a/escodegen.js +++ b/escodegen.js @@ -1208,7 +1208,8 @@ if (isStatement(stmt.declaration)) { result = join(result, this.generateStatement(stmt.declaration, bodyFlags)); } else { - result = join(result, this.generateExpression(stmt.declaration, Precedence.Assignment, E_TTT) + this.semicolon(flags)); + result = join(result, this.generateExpression(stmt.declaration, Precedence.Assignment, E_TTT)); + result.push(this.semicolon(flags)); } return result; }, diff --git a/test/source-map.js b/test/source-map.js index 8f6f2150..a970219f 100644 --- a/test/source-map.js +++ b/test/source-map.js @@ -520,4 +520,182 @@ describe('source map test', function () { expect(result.code).to.be.a('string'); expect(result.map).to.be.equal(null); }); + + it('ExportDefaultDeclaration test', function () { + var ast = { + "type": "Program", + "body": [ + { + "type": "ExportDefaultDeclaration", + "declaration": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "key": { + "type": "Identifier", + "name": "a", + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 2 + } + } + }, + "computed": false, + "value": { + "type": "FunctionExpression", + "id": null, + "params": [], + "body": { + "type": "BlockStatement", + "body": [], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + "generator": false, + "expression": false, + "async": false, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + "kind": "init", + "method": true, + "shorthand": false, + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 7 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "FunctionExpression", + "id": null, + "params": [], + "body": { + "type": "BlockStatement", + "body": [], + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 16 + } + } + }, + "generator": false, + "expression": false, + "async": false, + "loc": { + "start": { + "line": 5, + "column": 2 + }, + "end": { + "line": 5, + "column": 16 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + ], + "sourceType": "module", + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 19 + } + } + }; + + + var result = escodegen.generate(ast, { + sourceMap: "export", + sourceMapWithCode: true + }); + + var map = JSON.parse(result.map.toString()); + expect(map.mappings.split(';').slice(0, 4).join(';')).to.not.be.equal('AAAA;AAAA;AAAA;AAAA'); + }); });