Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking: provide ESM export (refs eslint/rfcs#72) #469

Merged
merged 29 commits into from Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
e6bc8c7
Build: generate es and cjs modules. Fixes #457
mreinstein Feb 23, 2021
0cb01c0
Build: add note explaining lib/version.js and lint
mreinstein Feb 28, 2021
e529adc
Build: update unit and lint testing commands
mreinstein Feb 28, 2021
b65da90
Update .eslintrc.cjs
mreinstein Feb 28, 2021
14f33cd
Update package.json
mreinstein Feb 28, 2021
195a7f2
Chore: add commonjs unit tests and lint (fixes #469)
mreinstein Mar 2, 2021
9e82484
Chore: fix acorn unit test and lint (fixes #469)
mreinstein Mar 2, 2021
0032c52
Build: remove node 10.x from the test matrix (fixes #469)
mreinstein Mar 2, 2021
4f7a7c6
Build: add commonjs build step for CI (fixes #469)
mreinstein Mar 2, 2021
3eea341
Build: add node 10.x test as separate job
mreinstein Mar 2, 2021
d10bf63
Breaking: acorn 8.0.5
mreinstein Mar 5, 2021
953b15a
Build: remove unnecessary tests
mreinstein Mar 5, 2021
c280899
Build: disable rollup treeshake
mreinstein Mar 9, 2021
90f1432
Update package.json
mreinstein Mar 9, 2021
144b092
Update tests/lib/commonjs.cjs
mreinstein Mar 9, 2021
97b2e3e
Update tests/lib/commonjs.cjs
mreinstein Mar 9, 2021
92fdab6
Update tests/lib/commonjs.cjs
mreinstein Mar 9, 2021
8af6e8c
Build: fix linting and remove unneeded ignore file
mreinstein Mar 9, 2021
c6cfa8a
Update tests/lib/commonjs.cjs
mreinstein Mar 9, 2021
bca83cd
Build: update eslint config
mreinstein Mar 9, 2021
d44d2fa
Chore: replace String.indexOf with String.includes
mreinstein Mar 9, 2021
2b3f5d9
Chore: use pathToFileURL to hopefully fix esm based tests on windows
mreinstein Mar 9, 2021
cbbf850
Chore: use pathToFileURL to hopefully fix esm based tests on windows
mreinstein Mar 9, 2021
30bd6e6
Chore: use pathToFileURL to hopefully fix esm based tests on windows
mreinstein Mar 9, 2021
a4df258
replace tap with mocha and minor dep updates
mreinstein Mar 13, 2021
8ab5181
Fix Node 15 peer deps issue
mreinstein Mar 13, 2021
f3af763
Update package.json
mreinstein Apr 12, 2021
6a43c72
fix linting problems
mreinstein Apr 12, 2021
10dc394
add basic jsx test for commonjs build
mreinstein Apr 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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]
mreinstein marked this conversation as resolved.
Show resolved Hide resolved
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";
nzakas marked this conversation as resolved.
Show resolved Hide resolved

export default version;