Skip to content

Commit 8234c48

Browse files
Breaking: provide ESM export (refs eslint/rfcs#72) (#469)
* Build: generate es and cjs modules. Fixes #457 * Build: add note explaining lib/version.js and lint * Build: update unit and lint testing commands * Update .eslintrc.cjs Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update package.json Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Chore: add commonjs unit tests and lint (fixes #469) * Chore: fix acorn unit test and lint (fixes #469) * Build: remove node 10.x from the test matrix (fixes #469) * Build: add commonjs build step for CI (fixes #469) * Build: add node 10.x test as separate job * Breaking: acorn 8.0.5 * Build: remove unnecessary tests * Build: disable rollup treeshake * Update package.json Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update tests/lib/commonjs.cjs Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update tests/lib/commonjs.cjs Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update tests/lib/commonjs.cjs Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Build: fix linting and remove unneeded ignore file * Update tests/lib/commonjs.cjs Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Build: update eslint config * Chore: replace String.indexOf with String.includes * Chore: use pathToFileURL to hopefully fix esm based tests on windows * Chore: use pathToFileURL to hopefully fix esm based tests on windows * Chore: use pathToFileURL to hopefully fix esm based tests on windows * replace tap with mocha and minor dep updates * Fix Node 15 peer deps issue * Update package.json Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * fix linting problems * add basic jsx test for commonjs build Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 2080ce6 commit 8234c48

File tree

826 files changed

+1202
-1093
lines changed

Some content is hidden

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

826 files changed

+1202
-1093
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
!.eslintrc.js
21
/node_modules
32
/tests/fixtures
43
/tools

.eslintrc.js renamed to .eslintrc.cjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ module.exports = {
44
root: true,
55
extends: "eslint",
66
env: {
7-
node: true,
87
es6: true
98
},
109
overrides: [
1110
{
12-
files: ["tests/lib/*"],
11+
files: ["tests/lib/**"],
12+
parserOptions: {
13+
ecmaVersion: 2020
14+
},
1315
env: {
1416
mocha: true
1517
}

.github/workflows/ci.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ jobs:
1818
node-version: '12.x'
1919
- name: Install dependencies
2020
run: npm install
21+
- name: Build commonjs
22+
run: npm run rollup
2123
- name: Lint files
22-
run: node Makefile.js lint
24+
run: npm run lint
2325
test:
2426
name: Test
2527
strategy:
2628
matrix:
2729
os: [ubuntu-latest]
28-
node: [15.x, 14.x, 13.x, 12.x, 10.x, "10.12.0"]
30+
node: [15.x, 14.x, 13.x, 12.x]
2931
include:
3032
- os: windows-latest
3133
node: "12.x"
@@ -39,5 +41,29 @@ jobs:
3941
node-version: ${{ matrix.node }}
4042
- name: Install dependencies
4143
run: npm install
44+
if: ${{ !startswith(matrix.node, '15') }}
45+
- name: Install dependencies
46+
run: npm install --legacy-peer-deps
47+
if: ${{ startswith(matrix.node, '15') }}
48+
- name: Build commonjs
49+
run: npm run rollup
50+
- name: Run tests
51+
run: npm run unit
52+
testNode10:
53+
name: Test Node 10.x
54+
strategy:
55+
matrix:
56+
os: [ubuntu-latest]
57+
node: [10.x, "10.12.0"]
58+
runs-on: ${{ matrix.os }}
59+
steps:
60+
- uses: actions/checkout@v2
61+
- uses: actions/setup-node@v1
62+
with:
63+
node-version: ${{ matrix.node }}
64+
- name: Install dependencies
65+
run: npm install
66+
- name: Build commonjs
67+
run: npm run rollup
4268
- name: Run tests
43-
run: node Makefile.js test
69+
run: npm run unit:cjs

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
build
22
coverage
33
node_modules
4+
.DS_Store
5+
dist
46
npm-debug.log
57
_test.js
68
.idea

Makefile.js

Lines changed: 0 additions & 107 deletions
This file was deleted.

espree.js

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,14 @@
5656
*/
5757
/* eslint no-undefined:0, no-use-before-define: 0 */
5858

59-
"use strict";
59+
import * as acorn from "acorn";
60+
import jsx from "acorn-jsx";
61+
import astNodeTypes from "./lib/ast-node-types.js";
62+
import espree from "./lib/espree.js";
63+
import espreeVersion from "./lib/version.js";
64+
import visitorKeys from "eslint-visitor-keys";
65+
import { getLatestEcmaVersion, getSupportedEcmaVersions } from "./lib/options.js";
6066

61-
const acorn = require("acorn");
62-
const jsx = require("acorn-jsx");
63-
const astNodeTypes = require("./lib/ast-node-types");
64-
const espree = require("./lib/espree");
65-
const { getLatestEcmaVersion, getSupportedEcmaVersions } = require("./lib/options");
6667

6768
// To initialize lazily.
6869
const parsers = {
@@ -106,7 +107,7 @@ const parsers = {
106107
* @throws {SyntaxError} If the input code is invalid.
107108
* @private
108109
*/
109-
function tokenize(code, options) {
110+
export function tokenize(code, options) {
110111
const Parser = parsers.get(options);
111112

112113
// Ensure to collect tokens.
@@ -128,7 +129,7 @@ function tokenize(code, options) {
128129
* @returns {ASTNode} The "Program" AST node.
129130
* @throws {SyntaxError} If the input code is invalid.
130131
*/
131-
function parse(code, options) {
132+
export function parse(code, options) {
132133
const Parser = parsers.get(options);
133134

134135
return new Parser(options, code).parse();
@@ -138,15 +139,12 @@ function parse(code, options) {
138139
// Public
139140
//------------------------------------------------------------------------------
140141

141-
exports.version = require("./package.json").version;
142+
export const version = espreeVersion;
142143

143-
exports.tokenize = tokenize;
144-
145-
exports.parse = parse;
146144

147145
// Deep copy.
148146
/* istanbul ignore next */
149-
exports.Syntax = (function() {
147+
export const Syntax = (function() {
150148
let name,
151149
types = {};
152150

@@ -168,10 +166,10 @@ exports.Syntax = (function() {
168166
}());
169167

170168
/* istanbul ignore next */
171-
exports.VisitorKeys = (function() {
172-
return require("eslint-visitor-keys").KEYS;
169+
export const VisitorKeys = (function() {
170+
return visitorKeys.KEYS;
173171
}());
174172

175-
exports.latestEcmaVersion = getLatestEcmaVersion();
173+
export const latestEcmaVersion = getLatestEcmaVersion();
176174

177-
exports.supportedEcmaVersions = getSupportedEcmaVersions();
175+
export const supportedEcmaVersions = getSupportedEcmaVersions();

lib/ast-node-types.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* @author Nicholas C. Zakas
44
*/
55

6-
"use strict";
7-
86
//------------------------------------------------------------------------------
97
// Requirements
108
//------------------------------------------------------------------------------
@@ -15,7 +13,7 @@
1513
// Public
1614
//------------------------------------------------------------------------------
1715

18-
module.exports = {
16+
export default {
1917
AssignmentExpression: "AssignmentExpression",
2018
AssignmentPattern: "AssignmentPattern",
2119
ArrayExpression: "ArrayExpression",

lib/espree.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
"use strict";
2-
31
/* eslint-disable no-param-reassign*/
4-
const TokenTranslator = require("./token-translator");
5-
const { normalizeOptions } = require("./options");
2+
import TokenTranslator from "./token-translator.js";
3+
import { normalizeOptions } from "./options.js";
4+
65

76
const STATE = Symbol("espree's internal state");
87
const ESPRIMA_FINISH_NODE = Symbol("espree's esprimaFinishNode");
@@ -41,7 +40,7 @@ function convertAcornCommentToEsprimaComment(block, text, start, end, startLoc,
4140
return comment;
4241
}
4342

44-
module.exports = () => Parser => {
43+
export default () => Parser => {
4544
const tokTypes = Object.assign({}, Parser.acorn.tokTypes);
4645

4746
if (Parser.acornJsx) {
@@ -276,7 +275,7 @@ module.exports = () => Parser => {
276275
}
277276
}
278277

279-
if (result.type.indexOf("Function") > -1 && !result.generator) {
278+
if (result.type.includes("Function") && !result.generator) {
280279
result.generator = false;
281280
}
282281

lib/features.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* @author Nicholas C. Zakas
55
*/
66

7-
"use strict";
8-
97
//------------------------------------------------------------------------------
108
// Requirements
119
//------------------------------------------------------------------------------
@@ -16,7 +14,7 @@
1614
// Public
1715
//------------------------------------------------------------------------------
1816

19-
module.exports = {
17+
export default {
2018

2119
// React JSX parsing
2220
jsx: false,

lib/options.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* @author Kai Cataldo
44
*/
55

6-
"use strict";
7-
86
//------------------------------------------------------------------------------
97
// Helpers
108
//------------------------------------------------------------------------------
@@ -67,7 +65,7 @@ function normalizeSourceType(sourceType = "script") {
6765
* @throws {Error} throw an error if found invalid option.
6866
* @returns {Object} normalized options
6967
*/
70-
function normalizeOptions(options) {
68+
export function normalizeOptions(options) {
7169
const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
7270
const sourceType = normalizeSourceType(options.sourceType);
7371
const ranges = options.range === true;
@@ -83,24 +81,14 @@ function normalizeOptions(options) {
8381
* Get the latest ECMAScript version supported by Espree.
8482
* @returns {number} The latest ECMAScript version.
8583
*/
86-
function getLatestEcmaVersion() {
84+
export function getLatestEcmaVersion() {
8785
return SUPPORTED_VERSIONS[SUPPORTED_VERSIONS.length - 1];
8886
}
8987

9088
/**
9189
* Get the list of ECMAScript versions supported by Espree.
9290
* @returns {number[]} An array containing the supported ECMAScript versions.
9391
*/
94-
function getSupportedEcmaVersions() {
92+
export function getSupportedEcmaVersions() {
9593
return [...SUPPORTED_VERSIONS];
9694
}
97-
98-
//------------------------------------------------------------------------------
99-
// Public
100-
//------------------------------------------------------------------------------
101-
102-
module.exports = {
103-
normalizeOptions,
104-
getLatestEcmaVersion,
105-
getSupportedEcmaVersions
106-
};

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy