Conversation
|
Thanks for the PR, this is a great start!
These are devDependencies, and so perfectly fine since they will be installed only by maintainers. I think what we might want here instead though is to make ES module the primary source, and auto-generate CommonJS instead. This would make the code that maintainers actually work with use modern syntax, and CommonJS a production artifact for older versions of Node, which also makes it easier to deprecate it altogether in some far future when everyone migrates. |
…JS module by rollup.
|
I've transformed all codes to ES6 import/export syntax, including the test. And use these to generate a CommonJS module. But there is a problem with That will change the |
index.js
Outdated
| } | ||
|
|
||
| module.exports = function(options) { | ||
| var acornJsx = function(options) { |
There was a problem hiding this comment.
This can be a function declaration.
test/run.js
Outdated
| } | ||
|
|
||
| const acorn = require("acorn"), jsx = require("..") | ||
| // const acorn = require("acorn"), jsx = require("..") |
Yeah that makes sense. Note that you couldn't use an However, that property was added mainly for backwards compatibility and the right way to use it is now via the value returned from the factory function. I wonder if, together with this change, we could just get rid of it and make a major bump... |
|
Okey, all left over comments were removed, and acornJsx is changed to function declaration. But I'm not very familiar with |
|
Any update on this? |
|
Thank you both for the hard work!!! |
index.cjs.js
Outdated
| @@ -0,0 +1,747 @@ | |||
| // DO NOT edit this file, it's auto generate from 'constructor/build.js', any changes will be overwrite. | |||
There was a problem hiding this comment.
Should this file be in .gitignore since it is generated?
There was a problem hiding this comment.
Yes, I have added it to .gitignore.
|
@elevatebart Emm, in this PR, I also changed the test scripts to use |
|
Any updates available or anything anyone can do to help push this along? |
|
|
||
| const XHTMLEntities = require('./xhtml'); | ||
| import * as acorn from "acorn"; | ||
| import XHTMLEntities from './xhtml'; |
There was a problem hiding this comment.
I think this import would need to have an extension?
import XHTMLEntities from './xhtml.js';| "description": "Modern, fast React.js JSX parser", | ||
| "homepage": "https://github.com/acornjs/acorn-jsx", | ||
| "version": "5.3.1", | ||
| "main": "index.cjs.js", |
There was a problem hiding this comment.
also, I think we would want to add "type": "module" to package.json as well
I've checked out the source code of
acorn, so that decided to use the same bundler(rollup) to generate the ES Module version ofacorn-jsx. And useindex.mjsas the filename of the ES Module, just likeacorn-jsxdo.However, I also noticed that
acorn-jsxis zero-dependencies for now. I don't know if it's acceptable to include a new dependency. Actually, the easiest way to do that is RegExp + String replace, but without lexical analysis, it will bring new issues in the future.At last, if someone wants to use
acorn-jsxinDeno, you should configure an imports map like below:Because
acorn-jsxhas a propertytokTypesthat relies onacorn, in the ES Module ofacorn-jsxit is imported byimport "acorn";.