-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add support for ES Module #113
base: main
Are you sure you want to change the base?
Changes from 1 commit
9da643a
9ff4c42
b399342
d60fa99
12f4a5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict'; | ||
|
||
const XHTMLEntities = require('./xhtml'); | ||
import * as acorn from "acorn"; | ||
import XHTMLEntities from './xhtml'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this import XHTMLEntities from './xhtml.js'; |
||
|
||
const hexNumber = /^[\da-fA-F]+$/; | ||
const decimalNumber = /^\d+$/; | ||
|
@@ -70,7 +71,7 @@ function getQualifiedJSXName(object) { | |
getQualifiedJSXName(object.property); | ||
} | ||
|
||
module.exports = function(options) { | ||
var acornJsx = function(options) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a function declaration. |
||
options = options || {}; | ||
return function(Parser) { | ||
return plugin({ | ||
|
@@ -82,16 +83,24 @@ 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; | ||
|
||
// If use this, rollup will bundle as `exports.default` and `exports.tokTypes`. That make the CommonJS users have to change their require code like `require("acorn-jsx").default`. | ||
|
||
// let tokTypes = acornJsx.tokTypes; | ||
// export { tokTypes }; | ||
|
||
function plugin(options, Parser) { | ||
const acorn = Parser.acorn || require("acorn"); | ||
const acorn = Parser.acorn || acorn; | ||
const acornJsx = getJsxTokens(acorn); | ||
const tt = acorn.tokTypes; | ||
const tok = acornJsx.tokTypes; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
"description": "Modern, fast React.js JSX parser", | ||
"homepage": "https://github.com/acornjs/acorn-jsx", | ||
"version": "5.2.0", | ||
"module": "index.mjs", | ||
"main": "index.cjs.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, I think we would want to add |
||
"module": "index.js", | ||
"maintainers": [ | ||
{ | ||
"name": "Ingvar Stepanyan", | ||
|
@@ -17,15 +18,16 @@ | |
}, | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "node test/run.js", | ||
"prepublishOnly": "node constructor/build.js" | ||
"test": "node -r esm test/run.js", | ||
"prepublishOnly": "node -r esm constructor/build.js" | ||
}, | ||
"peerDependencies": { | ||
"acorn": "^6.0.0 || ^7.0.0" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^12.0.0", | ||
"acorn": "^7.0.0", | ||
"esm": "^3.2.25", | ||
"rollup": "^2.12.0" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
var driver = require("./driver.js"); | ||
require("./tests-jsx.js"); | ||
require("./tests-misc.js"); | ||
import * as driver from "./driver.js"; | ||
import "./tests-jsx.js"; | ||
import "./tests-misc.js"; | ||
import * as acorn from "acorn"; | ||
import jsx from "../index.js"; | ||
|
||
function group(name) { | ||
if (typeof console === "object" && console.group) { | ||
|
@@ -18,7 +20,7 @@ function log(title, message) { | |
if (typeof console === "object") console.log(title, message); | ||
} | ||
|
||
const acorn = require("acorn"), jsx = require("..") | ||
// const acorn = require("acorn"), jsx = require("..") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a leftover? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (same for few other comments) |
||
const Parser = acorn.Parser.extend(jsx()) | ||
|
||
var stats, modes = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module.exports = { | ||
export default { | ||
quot: '\u0022', | ||
amp: '&', | ||
apos: '\u0027', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be in
.gitignore
since it is generated?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have added it to
.gitignore
.