Skip to content

Commit 57db900

Browse files
committed
Added support for exported field of ExportAllDeclaration
1 parent 9674ed5 commit 57db900

File tree

6 files changed

+110
-4
lines changed

6 files changed

+110
-4
lines changed

escodegen.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,14 +1274,23 @@
12741274

12751275
ExportAllDeclaration: function (stmt, flags) {
12761276
// export * FromClause ;
1277-
return [
1277+
var result = [
12781278
'export' + space,
1279-
'*' + space,
1279+
'*' + space
1280+
];
1281+
1282+
if (stmt.exported) {
1283+
result.push('as ' + stmt.exported.name + ' ');
1284+
}
1285+
1286+
result = join(result, [
12801287
'from' + space,
12811288
// ModuleSpecifier
12821289
this.generateExpression(stmt.source, Precedence.Sequence, E_TTT),
12831290
this.semicolon(flags)
1284-
];
1291+
]);
1292+
1293+
return result;
12851294
},
12861295

12871296
ExpressionStatement: function (stmt, flags) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"source-map": "~0.6.1"
4040
},
4141
"devDependencies": {
42-
"acorn": "^7.1.0",
42+
"acorn": "^8.0.1",
4343
"bluebird": "^3.4.7",
4444
"bower-registry-client": "^1.0.0",
4545
"chai": "^3.5.0",

test/compare-acorn-es2020.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright (C) 2012-2013 Yusuke Suzuki <utatane.tea@gmail.com>
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
17+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23+
*/
24+
25+
'use strict';
26+
27+
var fs = require('fs'),
28+
acorn = require('acorn'),
29+
escodegen = require('./loader'),
30+
chai = require('chai'),
31+
expect = chai.expect;
32+
33+
function test(code, expected) {
34+
var tree, actual, options, StringObject;
35+
36+
// alias, so that JSLint does not complain.
37+
StringObject = String;
38+
39+
options = {
40+
ranges: true,
41+
locations: false,
42+
ecmaVersion: 11,
43+
sourceType: 'module'
44+
};
45+
46+
tree = acorn.parse(code, options);
47+
48+
// for UNIX text comment
49+
actual = escodegen.generate(tree).replace(/[\n\r]$/, '') + '\n';
50+
expect(actual).to.be.equal(expected);
51+
}
52+
53+
function testMin(code, expected) {
54+
var tree, actual, options, StringObject;
55+
56+
// alias, so that JSLint does not complain.
57+
StringObject = String;
58+
59+
options = {
60+
ranges: true,
61+
locations: false,
62+
ecmaVersion: 11,
63+
sourceType: 'module'
64+
};
65+
66+
tree = acorn.parse(code, options);
67+
68+
// for UNIX text comment
69+
actual = escodegen.generate(tree, {
70+
format: escodegen.FORMAT_MINIFY,
71+
raw: false
72+
}).replace(/[\n\r]$/, '') + '\n';
73+
expect(actual).to.be.equal(expected);
74+
}
75+
76+
describe('compare acorn es2020 test', function () {
77+
fs.readdirSync(__dirname + '/compare-acorn-es2020').sort().forEach(function(file) {
78+
var code, expected, exp, min;
79+
if (/\.js$/.test(file) && !/expected\.js$/.test(file) && !/expected\.min\.js$/.test(file)) {
80+
it(file, function () {
81+
exp = file.replace(/\.js$/, '.expected.js');
82+
min = file.replace(/\.js$/, '.expected.min.js');
83+
code = fs.readFileSync(__dirname + '/compare-acorn-es2020/' + file, 'utf-8');
84+
expected = fs.readFileSync(__dirname + '/compare-acorn-es2020/' + exp, 'utf-8');
85+
test(code, expected);
86+
if (fs.existsSync(__dirname + '/compare-acorn-es2020/' + min)) {
87+
expected = fs.readFileSync(__dirname + '/compare-acorn-es2020/' + min, 'utf-8');
88+
testMin(code, expected);
89+
}
90+
});
91+
}
92+
});
93+
});
94+
/* vim: set sw=4 ts=4 et tw=80 : */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as name from 'OK';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export*as name from'OK'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as name from 'OK';

0 commit comments

Comments
 (0)