From 66944c8e78ab368d999a73d00fa5ddc7b6e900b0 Mon Sep 17 00:00:00 2001 From: clarkt Date: Fri, 8 Jun 2018 04:17:27 +0800 Subject: [PATCH 1/4] fix bug: sourcemap lost in export default declaration part --- escodegen.js | 3 +- package.json | 3 +- test/source-map.js | 178 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+), 2 deletions(-) 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/package.json b/package.json index 26560bc4..3eecb0a7 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,9 @@ "url": "http://github.com/estools/escodegen.git" }, "dependencies": { + "esprima": "^3.1.3", "estraverse": "^4.2.0", "esutils": "^2.0.2", - "esprima": "^3.1.3", "optionator": "^0.8.1" }, "optionalDependencies": { @@ -40,6 +40,7 @@ }, "devDependencies": { "acorn": "^4.0.4", + "babel-eslint": "^8.2.3", "bluebird": "^3.4.7", "bower-registry-client": "^1.0.0", "chai": "^3.5.0", diff --git a/test/source-map.js b/test/source-map.js index 8f6f2150..2a2e4c8d 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;'); + }); }); From 8c4489e63e856fc0546bd99581019ed4ef4b1572 Mon Sep 17 00:00:00 2001 From: tanglei02 Date: Fri, 8 Jun 2018 10:12:25 +0800 Subject: [PATCH 2/4] fix source map test --- package.json | 5 ++--- test/source-map.js | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3eecb0a7..b609e73a 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,9 @@ "url": "http://github.com/estools/escodegen.git" }, "dependencies": { - "esprima": "^3.1.3", "estraverse": "^4.2.0", "esutils": "^2.0.2", + "esprima": "^3.1.3", "optionator": "^0.8.1" }, "optionalDependencies": { @@ -40,7 +40,6 @@ }, "devDependencies": { "acorn": "^4.0.4", - "babel-eslint": "^8.2.3", "bluebird": "^3.4.7", "bower-registry-client": "^1.0.0", "chai": "^3.5.0", @@ -59,4 +58,4 @@ "build-min": "./node_modules/.bin/cjsify -ma path: tools/entry-point.js > escodegen.browser.min.js", "build": "./node_modules/.bin/cjsify -a path: tools/entry-point.js > escodegen.browser.js" } -} +} \ No newline at end of file diff --git a/test/source-map.js b/test/source-map.js index 2a2e4c8d..c6f26dfc 100644 --- a/test/source-map.js +++ b/test/source-map.js @@ -696,6 +696,6 @@ describe('source map test', function () { }); var map = JSON.parse(result.map.toString()); - expect(map.mappings.split(';').slice(0, 4).join(';')).to.not.be.equal('"AAAA;AAAA;AAAA;AAAA;'); + expect(map.mappings.split(';').slice(0, 4).join(';')).to.not.be.equal('"AAAA;AAAA;AAAA;AAAA'); }); }); From 43d3832573d8927143080b276d96da9ba5b323f1 Mon Sep 17 00:00:00 2001 From: clark-t Date: Fri, 8 Jun 2018 10:30:01 +0800 Subject: [PATCH 3/4] reset to original package json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b609e73a..26560bc4 100644 --- a/package.json +++ b/package.json @@ -58,4 +58,4 @@ "build-min": "./node_modules/.bin/cjsify -ma path: tools/entry-point.js > escodegen.browser.min.js", "build": "./node_modules/.bin/cjsify -a path: tools/entry-point.js > escodegen.browser.js" } -} \ No newline at end of file +} From 74dd05b006911b8722ca3ddeddafaff3db1594f4 Mon Sep 17 00:00:00 2001 From: clark-t Date: Fri, 8 Jun 2018 10:36:37 +0800 Subject: [PATCH 4/4] fix sourcemap test equal condition --- test/source-map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/source-map.js b/test/source-map.js index c6f26dfc..a970219f 100644 --- a/test/source-map.js +++ b/test/source-map.js @@ -696,6 +696,6 @@ describe('source map test', function () { }); var map = JSON.parse(result.map.toString()); - expect(map.mappings.split(';').slice(0, 4).join(';')).to.not.be.equal('"AAAA;AAAA;AAAA;AAAA'); + expect(map.mappings.split(';').slice(0, 4).join(';')).to.not.be.equal('AAAA;AAAA;AAAA;AAAA'); }); });