-
-
Notifications
You must be signed in to change notification settings - Fork 87
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
Compiler plugins #280
Compiler plugins #280
Conversation
/cc @sirinath |
* master: v2.5.6 revert version comment out failing test add docs site fix equation parsing issues v2.5.5 comment out failing equation test lots of bugfixes v2.5.4
Main question is about whether async behavior is a natural extension since there are a number of use-cases. (fetching remote data, inlining base64 images, more?) It's fine if the answer is "no", but just curious. |
(Oh, and also this is awesome! <3) |
Great point - we probably do want to support async. One option would be to determine if things are async would be to check if the plugin takes a callback, e.g. async callbacks const AST = require('idyll-ast');
module.exports = (ast, cb) => {
cb(AST.appendNode(ast, AST.createNode('div', {}, 'Hello World!') ));
}; or just check if the function provided is async? This feels like a little fancy but maybe people are used to the syntax by now? async functions const AST = require('idyll-ast');
module.exports = async (ast) => {
const myValue = await fetch(...);
return AST.appendNode(ast, AST.createNode('div', {}, myValue) ));
}; |
TBH I've never actually used |
The last commit adds support for asynchronous plugins via callbacks:
The compiler is completely synchronous ATM, so this change required updating the API to support asynchronous usage - I'll update the dependents to reflect this. |
* master: Update README.md docs: update component categories Reverted change to yarn.lock Updated babelify config to ignore node_modules. Update README.md better error handling Update README.md Update README.md v2.5.7 lexer hotfix add support for single quotes around string-type props
This is published in |
This adds support for custom compile-time plugins. This feature has been discussed in #70 quite a bit, and should enable fun things like references, tables of contents, etc. Some other use cases could be shelling out to other languages like r/python (or DSLs like vega-lite, penrose) to generate charts at compile time, fetching dynamic data, code linting, spellchecking, etc.
I've added a new module, idyll-ast, that will be useful for plugin authors who want to manipulate the AST somehow. This module is factored out of the compiler, which now depends on it, so it should be pretty stable.
Here's how it works: you define a plugin and the plugin receives the AST as input. It can modify this however it wants, and the results will be passed on to the runtime. A very simple example:
That is all. Right now it is expected that each of the plugins will be a standalone JS module. You can configure Idyll to use plugins in the following ways:
via package.json
via API
in browser (manually)
I'm happy to make API changes if people have preferences. I'll be testing this a bit more before merge.
Notifying folks who participated on the previous discussion:
/cc @rreusser @dundalek @heathermiller @bclinkinbeard