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 1 commit
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.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
!.eslintrc.js
!.eslintrc.cjs
mreinstein marked this conversation as resolved.
Show resolved Hide resolved
/node_modules
/tests/fixtures
/tools
23 changes: 23 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
root: true,
extends: "eslint:recommended",
mreinstein marked this conversation as resolved.
Show resolved Hide resolved
parserOptions: {
sourceType: "module"
},
env: {
es6: true,
node: true
},
overrides: [
{
files: ["tests/lib/*"],
parserOptions: {
ecmaVersion: 2020,
sourceType: "module"
},
env: {
mocha: true
}
}
]
};
18 changes: 0 additions & 18 deletions .eslintrc.js

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
9 changes: 4 additions & 5 deletions lib/espree.js
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions lib/features.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const version = "7.3.1";
nzakas marked this conversation as resolved.
Show resolved Hide resolved

export default version;
4 changes: 1 addition & 3 deletions lib/visitor-keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
* SOFTWARE.
*/

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
Expand All @@ -37,7 +35,7 @@
// Public
//------------------------------------------------------------------------------

module.exports = {
export default {

// ECMAScript
AssignmentExpression: ["left", "right"],
Expand Down
Loading