diff --git a/README.md b/README.md index a28dccd..cde1529 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ This is plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast Java It was created as an experimental alternative, faster [React.js JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) parser. Later, it replaced the [official parser](https://github.com/facebookarchive/esprima) and these days is used by many prominent development tools. +> This is a fork intended to satisfy a specific use case while awaiting the migration of the original package to ESM - https://github.com/acornjs/acorn-jsx/issues/112 + ## Transpiler Please note that this tool only parses source code to JSX AST, which is useful for various language tools and services. If you want to transpile your code to regular ES5-compliant JavaScript with source map, check out [Babel](https://babeljs.io/) and [Buble](https://buble.surge.sh/) transpilers which use `acorn-jsx` under the hood. @@ -19,7 +21,7 @@ Requiring this module provides you with an Acorn plugin that you can use like th ```javascript var acorn = require("acorn"); -var jsx = require("acorn-jsx"); +var jsx = require("@projectevergreen/acorn-jsx-esm"); acorn.Parser.extend(jsx()).parse("my(, 'code');"); ``` diff --git a/index.js b/index.js index 004e080..7934f08 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ -'use strict'; - -const XHTMLEntities = require('./xhtml'); +import * as acorn from "acorn"; +import XHTMLEntities from './xhtml.js'; const hexNumber = /^[\da-fA-F]+$/; const decimalNumber = /^\d+$/; @@ -70,7 +69,7 @@ function getQualifiedJSXName(object) { getQualifiedJSXName(object.property); } -module.exports = function(options) { +function acornJsx(options) { options = options || {}; return function(Parser) { return plugin({ @@ -82,14 +81,16 @@ module.exports = function(options) { // This is `tokTypes` of the peer dep. // This can be different instances from the actual `tokTypes` this plugin uses. -Object.defineProperty(module.exports, "tokTypes", { +Object.defineProperty(acornJsx, "tokTypes", { get: function get_tokTypes() { - return getJsxTokens(require("acorn")).tokTypes; + return getJsxTokens(acorn).tokTypes }, configurable: true, enumerable: true }); +export default acornJsx; + function plugin(options, Parser) { const acorn = Parser.acorn || require("acorn"); const acornJsx = getJsxTokens(acorn); diff --git a/package.json b/package.json index 6debde9..c15ae1d 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,15 @@ { - "name": "acorn-jsx", + "name": "@projectevergreen/acorn-jsx-esm", "description": "Modern, fast React.js JSX parser", - "homepage": "https://github.com/acornjs/acorn-jsx", - "version": "5.3.2", + "homepage": "https://github.com/ProjectEvergreen/acorn-jsx-esm", + "version": "0.1.0", + "type": "module", + "publishConfig": { + "access": "public" + }, + "exports": { + ".": "./index.js" + }, "maintainers": [ { "name": "Ingvar Stepanyan", @@ -12,7 +19,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/acornjs/acorn-jsx" + "url": "https://github.com/ProjectEvergreen/acorn-jsx-esm" }, "license": "MIT", "scripts": { diff --git a/xhtml.js b/xhtml.js index c152009..8f5aa79 100644 --- a/xhtml.js +++ b/xhtml.js @@ -1,4 +1,4 @@ -module.exports = { +export default { quot: '\u0022', amp: '&', apos: '\u0027',