-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Next Major: Simplifying the API, docs and the plugins, smaller codebase, TypeScript support #65
Comments
Would be great. Also, while we are at it, some other things could make using parse-function much easier: TypeScript definitions. Currently it's difficult to use parse-function in TypeScript project because of the lack of definition. We currently have to import parse-function using Webpack will resolve the By having a definition, we would be able to use the See that issue to see the impact of that on a real project: |
I'm not so in TypeScript, so definitions are always welcome as PR. |
I can take care of that. Since your project is not written in TS, it's better to host then in DefinitelyTyped repository. If you don't mind, I'll add them there. |
Great, yea! :) |
I'll handle that. I already moved the source code to new home at my monorepo https://github.com/tunnckoCore/opensource/tree/master/packages/parse-function, so it will eventually get written in typescript.
|
Final API for v6, defaults to use import { parse as acornParse } from 'acorn';
import { parseFunction } from '.';
// `node` is an AST Node
function bobbyPlugin(node, result) {
const bobby = 'bobby';
return { ...result, bobby };
}
function barryPlugin(node, result) {
return { ...result, barry: 'barry barry' };
}
const result = parseFunction('function foo(bar, qux) {}', {
parse: acornParse,
plugins: [bobbyPlugin, barryPlugin], // supports array of plugins
parserOptions: {},
});
console.log(result); It also has some TypeScript support. For more, PRs welcome. |
BREAKING CHANGE: exports named `parseFunction`, For more see #65 (comment) Signed-off-by: Charlike Mike Reagent <opensource@tunnckocore.com>
What about that?
We are just removing the extra step of creating "app" instance and then calling
parse
.Also removing the
use
so called "smart plugins", we don't need to change anything to that "app" instance.So now plugins are more simpler and flat, instead of
(app) => (node, result) => {}
Should be noted that we can't just add
plugins
property to theparserOptions
, because will conflict withbabylon
for example.The text was updated successfully, but these errors were encountered: