Skip to content

Commit 267899b

Browse files
committed
feat: switch to ESM source and distributions
BREAKING CHANGE: Adds `exports` Also: 1. updates benchmark 2. fixes escodegen with missing options
1 parent 5f23e07 commit 267899b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2358
-4346
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ indent_style = space
1212
indent_size = 4
1313

1414
[*.json]
15-
indent_size = 2
15+
indent_size = 4
1616

1717
[*.yml]
1818
indent_size = 2

.eslintignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ coverage
66

77
test/*/*.js
88

9-
escodegen.browser.min.js
10-
escodegen.browser.js
9+
dist

.eslintrc.js .eslintrc.cjs

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ module.exports = {
77
SharedArrayBuffer: 'readonly'
88
},
99
env: {
10-
node: true,
1110
es6: true
1211
},
1312
parserOptions: {
1413
sourceType: 'module',
15-
ecmaVersion: 2018
14+
ecmaVersion: 2020
1615
},
1716
overrides: [{
17+
files: ['*-node.js', '.eslintrc.cjs', 'benchmark/**', 'bin/**', 'tools/**'],
18+
env: {
19+
node: true
20+
}
21+
}, {
1822
files: '.eslintrc.js',
1923
parserOptions: {
2024
sourceType: 'script'

.gitignore

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ node_modules/
88
# Cover
99
.coverage_data/
1010
cover_html/
11+
coverage
12+
13+
.idea
1114

1215
npm-debug.log
1316

14-
escodegen.browser.min.js
15-
escodegen.browser.js
17+
dist

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ for a demo.
1616
Escodegen can be used in a web browser:
1717

1818
```html
19-
<script src="escodegen.browser.js"></script>
19+
<script src="dist/escodegen.umd.js"></script>
2020
```
2121

22-
escodegen.browser.js can be found in tagged revisions on GitHub.
22+
`dist/escodegen.umd.js` can be found in tagged revisions on GitHub.
2323

2424
Or in a Node.js application via npm:
2525

@@ -54,7 +54,7 @@ After that,
5454
npm run-script build
5555
```
5656

57-
will generate `escodegen.browser.js`, which can be used in browser environments.
57+
will generate `dist/escodegen.umd.js`, which can be used in browser environments.
5858

5959
And,
6060

benchmark/asts.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
var fs = require('fs'),
2-
path = require('path'),
3-
esprima = require('esprima');
1+
import fs from 'fs';
2+
import path from 'path';
3+
import { dirname } from 'path';
4+
import { fileURLToPath } from 'url';
45

5-
var FILES_PATH = path.join(__dirname, './asts');
6+
// import esprima from 'esprima';
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
const FILES_PATH = path.join(__dirname, './asts');
610

711
var FILES = [
812
'jQuery 1.7.1',
@@ -22,8 +26,8 @@ function slug(name) {
2226
return name.toLowerCase().replace(/\s/g, '-');
2327
}
2428

25-
module.exports = FILES.map(function (file) {
26-
var astJson = fs.readFileSync(FILES_PATH + '/' + slug(file) + '-ast.json');
29+
export default FILES.map(function (file) {
30+
const astJson = fs.readFileSync(`${FILES_PATH}/${slug(file)}-ast.json`);
2731

2832
return JSON.parse(astJson);
2933
});

benchmark/index.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
var Benchmark = require('benchmark'),
2-
escodegen = require('../'),
3-
old = require('./old.js'),
4-
esotope = require('esotope'),
5-
asts = require('./asts');
6-
1+
import Benchmark from 'benchmark';
2+
import esotope from 'esotope';
3+
import * as escodegen from '../src/escodegen-node.js';
4+
import old from './old.cjs';
5+
import asts from './asts.js';
76

87
function cycle(codegen) {
98
for (var i = 0; i < asts.length; i++)
@@ -32,7 +31,7 @@ new Benchmark.Suite()
3231
})
3332

3433
.on('complete', function () {
35-
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
34+
console.log(`Fastest is ${this.filter('fastest').map('name')}`);
3635

3736
console.log('esotope is x' + (this[0].hz / this[1].hz).toFixed(2) + ' times faster vs escodegen.');
3837
})

benchmark/old.js benchmark/old.cjs

File renamed without changes.

benchmark/package-lock.json

+126
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmark/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
{
2+
"private": true,
23
"name": "benchmark",
34
"version": "0.1.0",
45
"description": "Regression benchmarking. Compare speed with upstream npm version",
56
"main": "index.js",
7+
"type": "module",
68
"scripts": {
79
"test": "node index"
810
},
911
"author": "Ivan Nikulin <[email protected]>",
1012
"license": "MIT",
1113
"dependencies": {
12-
"benchmark": "~1.0.0",
14+
"benchmark": "~2.1.4",
1315
"esotope": "*"
1416
},
1517
"optionalDependencies": {
16-
"microtime": "~0.4.0"
18+
"microtime": "~3.0.0"
1719
}
1820
}

benchmark/trace_cycle.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
var asts = require('./asts'),
2-
escodegen = require('../');
1+
import asts from './asts.js';
2+
import escodegen from '../src/escodegen-node.js';
33

44
for (var j = 0; j < 50; j++) {
55
for (var i = 0; i < asts.length; i++)
66
escodegen.generate(asts[0]);
77
}
8-

bin/escodegen.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@
2323
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
/*jslint sloppy:true node:true */
26+
import fs from 'fs';
27+
import path from 'path';
28+
import esprima from 'esprima';
29+
import Optionator from 'optionator';
30+
import * as escodegen from '../src/escodegen-node.js';
2731

28-
var fs = require('fs'),
29-
path = require('path'),
30-
root = path.join(path.dirname(fs.realpathSync(__filename)), '..'),
31-
esprima = require('esprima'),
32-
escodegen = require(root),
33-
optionator = require('optionator')({
32+
const optionator = Optionator({
3433
prepend: 'Usage: escodegen [options] file...',
3534
options: [
3635
{
@@ -43,7 +42,6 @@ var fs = require('fs'),
4342
}),
4443
args = optionator.parse(process.argv),
4544
files = args._,
46-
options,
4745
esprimaOptions = {
4846
raw: true,
4947
tokens: true,
@@ -56,6 +54,7 @@ if (files.length === 0) {
5654
process.exit(1);
5755
}
5856

57+
let options;
5958
if (args.config) {
6059
try {
6160
options = JSON.parse(fs.readFileSync(args.config, 'utf-8'));
@@ -68,7 +67,7 @@ files.forEach(function (filename) {
6867
var content = fs.readFileSync(filename, 'utf-8'),
6968
syntax = esprima.parse(content, esprimaOptions);
7069

71-
if (options.comment) {
70+
if (options && options.comment) {
7271
escodegen.attachComments(syntax, syntax.comments, syntax.tokens);
7372
}
7473

bin/esgenerate.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424
*/
2525

26-
/*jslint sloppy:true node:true */
26+
import fs from 'fs';
27+
import * as escodegen from '../src/escodegen-node.js';
28+
import Optionator from 'optionator';
2729

28-
var fs = require('fs'),
29-
path = require('path'),
30-
root = path.join(path.dirname(fs.realpathSync(__filename)), '..'),
31-
escodegen = require(root),
32-
optionator = require('optionator')({
30+
const optionator = Optionator({
3331
prepend: 'Usage: esgenerate [options] file.json ...',
3432
options: [
3533
{
@@ -41,14 +39,15 @@ var fs = require('fs'),
4139
]
4240
}),
4341
args = optionator.parse(process.argv),
44-
files = args._,
45-
options;
42+
files = args._;
4643

4744
if (files.length === 0) {
4845
console.log(optionator.generateHelp());
4946
process.exit(1);
5047
}
5148

49+
let options;
50+
5251
if (args.config) {
5352
try {
5453
options = JSON.parse(fs.readFileSync(args.config, 'utf-8'));

escodegen.js.map

-1
This file was deleted.

0 commit comments

Comments
 (0)