From 4e53423c857f758a8b3d6e9cf785658ef6848847 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Sat, 10 Feb 2024 20:40:01 -0500 Subject: [PATCH 1/2] esm support --- README.md | 4 +++- index.js | 13 +++++++------ package.json | 15 +++++++++++---- xhtml.js | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a28dccd..bd2c167 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 and 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', From ddb0f62cc6dc5c622cb146e9c9139fe9ecc34605 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Sat, 10 Feb 2024 20:42:06 -0500 Subject: [PATCH 2/2] grammar --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd2c167..cde1529 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ 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 and awaiting the migration of the original package to ESM - https://github.com/acornjs/acorn-jsx/issues/112 +> 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