Skip to content
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

Object plugin #144

Merged
merged 13 commits into from
Jul 21, 2021
Merged

Object plugin #144

merged 13 commits into from
Jul 21, 2021

Conversation

6utt3rfly
Copy link
Collaborator

Adds Object Expression support as a plugin, from issue #39

(builds on #143)

NOTE: doesn't build into the dist folder yet...

…to source)

- Tests now restore original operation after running to avoid polluting other tests (since they modify static values versus instance values)
- filterProps test util now handles bool and null properly
@6utt3rfly
Copy link
Collaborator Author

@LeaVerou - I spent awhile playing with the rollup config, given that this is the first plugin. I could use your thoughts on how plugins should be bundled...

if the plugin is added by the end-user with a simple import '{plugin}', then that plugin needs to import jsep. If plugins are built as an extra step to a separate output file, then each plugin will create its own copy of Jsep (and then it wouldn't work for multiple plugins). I was able to add a replace import jsep from '../jsep.js' with just import jsep from 'jsep', and then a custom plugin to prevent including the jsep file in the output, but that makes it more problematic if using a minified, iife, cjs, or other version.

{
  name: 'ignore-import',
  resolveId: source => source.includes(name) ? null : false,
},

If each plugin is a function that takes jsep as an argument, then it would not have any imports and could be bundled as separate file easily. Using a plugin would then be like:

import jsep from 'jsep';
import plugin from '...';

jsep.addPlugin(plugin)
// or:
plugin(jsep);

I looked at our discussion in #123 ... but thought you might have some further thoughts on how to proceed?

6utt3rfly and others added 5 commits June 10, 2021 22:00
…ependency injection

- Added plugin registration to JSEP. Plugins have a `name` and an `init` function that is called on registration with JSEP.
- Updated Object + Ternary plugins. Ternary plugin is registered by default
- Updated rollup to build each plugin as a separate output (all formats). Also delete dist folder before building.
- don't pollute the JSEP namespace from plugins. Use local constants instead.
Co-authored-by: Lea Verou <lea@verou.me>
(single object arg, single array of objects arg, multiple objects arg)
…to readme

- gobbleExpression and gobbleToken need to stop running hooks once a node is found, similar to how jsep checks when calling each successive gobble method now. This saves each hook from having to check for `env.node` (and potentially leading to future errors with 2 hooks parsing 2 sequential expressions as just the last node). Added unit tests.
Update plugin system to use registration
@6utt3rfly 6utt3rfly changed the base branch from master to plugin-system July 21, 2021 16:20
@6utt3rfly 6utt3rfly marked this pull request as ready for review July 21, 2021 16:20
@6utt3rfly 6utt3rfly merged commit 2c0527a into plugin-system Jul 21, 2021
@6utt3rfly 6utt3rfly deleted the plugin-object branch August 1, 2021 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant