Skip to content

Commit

Permalink
Breaking: provide ESM export (refs eslint/rfcs#72) (#469)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mreinstein and mdjermanovic committed Apr 16, 2021
1 parent 2080ce6 commit 8234c48
Show file tree
Hide file tree
Showing 826 changed files with 1,202 additions and 1,093 deletions.
1 change: 0 additions & 1 deletion .eslintignore
@@ -1,4 +1,3 @@
!.eslintrc.js
/node_modules
/tests/fixtures
/tools
6 changes: 4 additions & 2 deletions .eslintrc.js → .eslintrc.cjs
Expand Up @@ -4,12 +4,14 @@ module.exports = {
root: true,
extends: "eslint",
env: {
node: true,
es6: true
},
overrides: [
{
files: ["tests/lib/*"],
files: ["tests/lib/**"],
parserOptions: {
ecmaVersion: 2020
},
env: {
mocha: true
}
Expand Down
32 changes: 29 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -18,14 +18,16 @@ jobs:
node-version: '12.x'
- name: Install dependencies
run: npm install
- name: Build commonjs
run: npm run rollup
- name: Lint files
run: node Makefile.js lint
run: npm run lint
test:
name: Test
strategy:
matrix:
os: [ubuntu-latest]
node: [15.x, 14.x, 13.x, 12.x, 10.x, "10.12.0"]
node: [15.x, 14.x, 13.x, 12.x]
include:
- os: windows-latest
node: "12.x"
Expand All @@ -39,5 +41,29 @@ jobs:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
if: ${{ !startswith(matrix.node, '15') }}
- name: Install dependencies
run: npm install --legacy-peer-deps
if: ${{ startswith(matrix.node, '15') }}
- name: Build commonjs
run: npm run rollup
- name: Run tests
run: npm run unit
testNode10:
name: Test Node 10.x
strategy:
matrix:
os: [ubuntu-latest]
node: [10.x, "10.12.0"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm install
- name: Build commonjs
run: npm run rollup
- name: Run tests
run: node Makefile.js test
run: npm run unit:cjs
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,6 +1,8 @@
build
coverage
node_modules
.DS_Store
dist
npm-debug.log
_test.js
.idea
Expand Down
107 changes: 0 additions & 107 deletions Makefile.js

This file was deleted.

32 changes: 15 additions & 17 deletions espree.js
Expand Up @@ -56,13 +56,14 @@
*/
/* eslint no-undefined:0, no-use-before-define: 0 */

"use strict";
import * as acorn from "acorn";
import jsx from "acorn-jsx";
import astNodeTypes from "./lib/ast-node-types.js";
import espree from "./lib/espree.js";
import espreeVersion from "./lib/version.js";
import visitorKeys from "eslint-visitor-keys";
import { getLatestEcmaVersion, getSupportedEcmaVersions } from "./lib/options.js";

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

// To initialize lazily.
const parsers = {
Expand Down Expand Up @@ -106,7 +107,7 @@ const parsers = {
* @throws {SyntaxError} If the input code is invalid.
* @private
*/
function tokenize(code, options) {
export function tokenize(code, options) {
const Parser = parsers.get(options);

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

return new Parser(options, code).parse();
Expand All @@ -138,15 +139,12 @@ function parse(code, options) {
// Public
//------------------------------------------------------------------------------

exports.version = require("./package.json").version;
export const version = espreeVersion;

exports.tokenize = tokenize;

exports.parse = parse;

// Deep copy.
/* istanbul ignore next */
exports.Syntax = (function() {
export const Syntax = (function() {
let name,
types = {};

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

/* istanbul ignore next */
exports.VisitorKeys = (function() {
return require("eslint-visitor-keys").KEYS;
export const VisitorKeys = (function() {
return visitorKeys.KEYS;
}());

exports.latestEcmaVersion = getLatestEcmaVersion();
export const latestEcmaVersion = getLatestEcmaVersion();

exports.supportedEcmaVersions = getSupportedEcmaVersions();
export const supportedEcmaVersions = getSupportedEcmaVersions();
4 changes: 1 addition & 3 deletions lib/ast-node-types.js
Expand Up @@ -3,8 +3,6 @@
* @author Nicholas C. Zakas
*/

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
Expand All @@ -15,7 +13,7 @@
// Public
//------------------------------------------------------------------------------

module.exports = {
export default {
AssignmentExpression: "AssignmentExpression",
AssignmentPattern: "AssignmentPattern",
ArrayExpression: "ArrayExpression",
Expand Down
11 changes: 5 additions & 6 deletions lib/espree.js
@@ -1,8 +1,7 @@
"use strict";

/* eslint-disable no-param-reassign*/
const TokenTranslator = require("./token-translator");
const { normalizeOptions } = require("./options");
import TokenTranslator from "./token-translator.js";
import { normalizeOptions } from "./options.js";


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

module.exports = () => Parser => {
export default () => Parser => {
const tokTypes = Object.assign({}, Parser.acorn.tokTypes);

if (Parser.acornJsx) {
Expand Down Expand Up @@ -276,7 +275,7 @@ module.exports = () => Parser => {
}
}

if (result.type.indexOf("Function") > -1 && !result.generator) {
if (result.type.includes("Function") && !result.generator) {
result.generator = false;
}

Expand Down
4 changes: 1 addition & 3 deletions lib/features.js
Expand Up @@ -4,8 +4,6 @@
* @author Nicholas C. Zakas
*/

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
Expand All @@ -16,7 +14,7 @@
// Public
//------------------------------------------------------------------------------

module.exports = {
export default {

// React JSX parsing
jsx: false,
Expand Down
18 changes: 3 additions & 15 deletions lib/options.js
Expand Up @@ -3,8 +3,6 @@
* @author Kai Cataldo
*/

"use strict";

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -67,7 +65,7 @@ function normalizeSourceType(sourceType = "script") {
* @throws {Error} throw an error if found invalid option.
* @returns {Object} normalized options
*/
function normalizeOptions(options) {
export function normalizeOptions(options) {
const ecmaVersion = normalizeEcmaVersion(options.ecmaVersion);
const sourceType = normalizeSourceType(options.sourceType);
const ranges = options.range === true;
Expand All @@ -83,24 +81,14 @@ function normalizeOptions(options) {
* Get the latest ECMAScript version supported by Espree.
* @returns {number} The latest ECMAScript version.
*/
function getLatestEcmaVersion() {
export function getLatestEcmaVersion() {
return SUPPORTED_VERSIONS[SUPPORTED_VERSIONS.length - 1];
}

/**
* Get the list of ECMAScript versions supported by Espree.
* @returns {number[]} An array containing the supported ECMAScript versions.
*/
function getSupportedEcmaVersions() {
export function getSupportedEcmaVersions() {
return [...SUPPORTED_VERSIONS];
}

//------------------------------------------------------------------------------
// Public
//------------------------------------------------------------------------------

module.exports = {
normalizeOptions,
getLatestEcmaVersion,
getSupportedEcmaVersions
};
4 changes: 1 addition & 3 deletions lib/token-translator.js
Expand Up @@ -4,8 +4,6 @@
*/
/* eslint no-underscore-dangle: 0 */

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -260,4 +258,4 @@ TokenTranslator.prototype = {
// Public
//------------------------------------------------------------------------------

module.exports = TokenTranslator;
export default TokenTranslator;
3 changes: 3 additions & 0 deletions lib/version.js
@@ -0,0 +1,3 @@
const version = "7.3.1";

export default version;

0 comments on commit 8234c48

Please sign in to comment.