Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions escodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,15 @@
return result;
},

ExportDefaultDeclaration: function (stmt, flags) {
stmt.default = true;
return this.ExportDeclaration(stmt, flags);
},

ExportNamedDeclaration: function (stmt, flags) {
return this.ExportDeclaration(stmt, flags);
},

ExpressionStatement: function (stmt, flags) {
var result, fragment;

Expand Down Expand Up @@ -2236,13 +2245,14 @@
},

ImportDefaultSpecifier: function (expr, precedence, flags) {
return generateIdentifier(expr.id);
return generateIdentifier(expr.id || expr.local);
},

ImportNamespaceSpecifier: function (expr, precedence, flags) {
var result = ['*'];
if (expr.id) {
result.push(space + 'as' + noEmptySpace() + generateIdentifier(expr.id));
var id = expr.id || expr.local;
if (id) {
result.push(space + 'as' + noEmptySpace() + generateIdentifier(id));
}
return result;
},
Expand All @@ -2252,7 +2262,7 @@
},

ExportSpecifier: function (expr, precedence, flags) {
var result = [ expr.id.name ];
var result = [ (expr.id || expr.local).name ];
if (expr.name) {
result.push(noEmptySpace() + 'as' + noEmptySpace() + generateIdentifier(expr.name));
}
Expand Down
File renamed without changes.
5,658 changes: 5,658 additions & 0 deletions test/3rdparty/esprima-2.5.0.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

'use strict';

var esprima = require('./3rdparty/esprima'),
var esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect,
Expand Down
2 changes: 1 addition & 1 deletion test/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'use strict';

var data,
esprima = require('./3rdparty/esprima'),
esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect;
Expand Down
106 changes: 106 additions & 0 deletions test/compare-esprima2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

'use strict';

var fs = require('fs'),
esprima = require('./3rdparty/esprima-2.5.0'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect,
DIR = 'compare-esprima2';

function test(code, expected) {
var tree, actual, options, StringObject;

// alias, so that JSLint does not complain.
StringObject = String;

options = {
range: true,
loc: false,
tokens: true,
raw: false,
comment: true,
sourceType: 'module'
};

tree = esprima.parse(code, options);

// for UNIX text comment
actual = escodegen.generate(tree).replace(/[\n\r]$/, '') + '\n';
expect(actual).to.be.equal(expected);
}

function testMin(code, expected) {
var tree, tree2, actual, actual2, options, StringObject;

// alias, so that JSLint does not complain.
StringObject = String;

options = {
range: true,
loc: false,
tokens: true,
raw: false,
sourceType: 'module'
};

tree = esprima.parse(code, options);

// for UNIX text comment
actual = escodegen.generate(tree, {
format: escodegen.FORMAT_MINIFY,
raw: false
}).replace(/[\n\r]$/, '') + '\n';
expect(actual).to.be.equal(expected);

// And ensure that minified value is exactly equal.
tree2 = esprima.parse(actual, options);
actual2 = escodegen.generate(tree2, {
format: escodegen.FORMAT_MINIFY,
raw: false
}).replace(/[\n\r]$/, '') + '\n';
expect(actual2).to.be.equal(actual);
}

describe('compare esprima 2 test', function () {
fs.readdirSync(__dirname + '/' + DIR).sort().forEach(function(file) {
var code, expected, exp, min;
if (/\.js$/.test(file) && !/expected\.js$/.test(file) && !/expected\.min\.js$/.test(file)) {
it(file, function () {
exp = file.replace(/\.js$/, '.expected.js');
min = file.replace(/\.js$/, '.expected.min.js');
code = fs.readFileSync(__dirname + '/' + DIR + '/' + file, 'utf-8');
expected = fs.readFileSync(__dirname + '/' + DIR + '/' + exp, 'utf-8');
test(code, expected);
if (fs.existsSync(__dirname + '/' + DIR + '/' + min)) {
expected = fs.readFileSync(__dirname + '/' + DIR + '/' + min, 'utf-8');
testMin(code, expected);
}
});
}
});
});
/* vim: set sw=4 ts=4 et tw=80 : */
2 changes: 2 additions & 0 deletions test/compare-esprima2/export-default-declaration.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default function a() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default function a(){}
3 changes: 3 additions & 0 deletions test/compare-esprima2/export-default-declaration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function a () { }
// export default var i = 20;
// export default const K = 20;
8 changes: 8 additions & 0 deletions test/compare-esprima2/import-with-default.expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import foo from 'foo';
import foo, * as foo from 'foo';
import * as foo from 'foo';
import ok, {
foo,
test,
logging
} from 'foo';
1 change: 1 addition & 0 deletions test/compare-esprima2/import-with-default.expected.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import foo from'foo';import foo,*as foo from'foo';import*as foo from'foo';import ok,{foo,test,logging}from'foo'
8 changes: 8 additions & 0 deletions test/compare-esprima2/import-with-default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import foo from 'foo';
import foo, * as foo from 'foo';
import * as foo from 'foo';
import ok, {
foo,
test,
logging
} from 'foo';
2 changes: 1 addition & 1 deletion test/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'use strict';

var fs = require('fs'),
esprima = require('./3rdparty/esprima'),
esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect;
Expand Down
2 changes: 1 addition & 1 deletion test/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

'use strict';

var esprima = require('./3rdparty/esprima'),
var esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect,
Expand Down
2 changes: 1 addition & 1 deletion test/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
'use strict';

var fs = require('fs'),
esprima = require('./3rdparty/esprima'),
esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect,
Expand Down
2 changes: 1 addition & 1 deletion test/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

'use strict';

var esprima = require('./3rdparty/esprima'),
var esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect,
Expand Down
2 changes: 1 addition & 1 deletion test/source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

'use strict';

var esprima = require('./3rdparty/esprima'),
var esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
sourcemap = require('source-map'),
chai = require('chai'),
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

'use strict';

var esprima = require('./3rdparty/esprima'),
var esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect,
Expand Down
2 changes: 1 addition & 1 deletion test/verbatim.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

'use strict';

var esprima = require('./3rdparty/esprima'),
var esprima = require('./3rdparty/esprima-1.0.0-dev'),
escodegen = require('./loader'),
chai = require('chai'),
expect = chai.expect,
Expand Down