Skip to content

Commit

Permalink
Merge e0f02d1 into 169b79f
Browse files Browse the repository at this point in the history
  • Loading branch information
tbranyen committed Nov 12, 2022
2 parents 169b79f + e0f02d1 commit 28b8416
Show file tree
Hide file tree
Showing 29 changed files with 1,889 additions and 4,771 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ jobs:
- uses: bahmutov/npm-install@v1.6.0
with:
useRollingCache: true
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: wasm32-unknown-unknown
- uses: jetli/wasm-bindgen-action@v0.1.0
with:
version: 'latest'
- run: rustup target add wasm32-unknown-unknown
- uses: browser-actions/setup-chrome@latest
- run: chrome --version
- run: lerna run build
- run: lerna run test-cov
- run: npm run build
- run: npm run test-cov
- name: Publish to coveralls.io
uses: coverallsapp/github-action@v1.1.2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ node_modules
dist
docs
coverage
target
lerna-debug.log
.__fixtures_*
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ the foundation of the diffHTML ecosystem.
components seamlessly. The API will be very familiar to anyone
who has used React as the class methods and structure are the same.

* [babel-plugin-transform-diffhtml](/packages/babel-plugin-transform-diffhtml)

```sh
npm install diffhtml-rust-parser
```

**Coming soon**

An alternative parser written in Rust, providing a wrapper around the
[tl](https://docs.rs/tl/latest/tl/) library.

* [babel-plugin-transform-diffhtml](/packages/babel-plugin-transform-diffhtml)

```sh
Expand Down
11 changes: 0 additions & 11 deletions packages/babel-plugin-transform-diffhtml/.babelrc

This file was deleted.

11 changes: 8 additions & 3 deletions packages/babel-plugin-transform-diffhtml/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"require": ["@babel/register"],
"colors": true
}
"require": ["test/_setup.js"],
"loader": "extless-loader",
"recursive": true,
"colors": true,
"bail": true,
"parallel": true,
"jobs": 2
}
18 changes: 18 additions & 0 deletions packages/babel-plugin-transform-diffhtml/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { parse } from 'diffhtml-rust-parser';

export default {
env: {
normal: {
plugins: [['module:./dist/es/index.js', { createTree: 'html' }]]
},

wasm: {
plugins: [
['module:./dist/es/index.js', {
createTree: 'html',
parse,
}]
]
}
},
};
1 change: 1 addition & 0 deletions packages/babel-plugin-transform-diffhtml/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
module.exports = require('./dist');
export * from './dist/
9 changes: 6 additions & 3 deletions packages/babel-plugin-transform-diffhtml/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { createTree, Internals } from 'diffhtml';
import * as babylon from 'babylon';

const { parse } = Internals;
const TOKEN = '__DIFFHTML_BABEL__';
const doctypeEx = /<!.*>/i;
const tokenEx = /__DIFFHTML_BABEL__([^_]*)__/;
Expand All @@ -16,7 +15,7 @@ let ident = {};
*
* @return {Object} containing the visitor handler.
*/
export default function({ types: t }) {
export default function({ types: t, ...rest }) {
const interpolateValues = (string, supplemental, createTreeNode) => {
// If this is text and not a doctype, add as a text node.
if (string && !doctypeEx.test(string) && !tokenEx.test(string)) {
Expand Down Expand Up @@ -145,6 +144,10 @@ export default function({ types: t }) {
tagName = memberExpressionToString(path.node.tag);
}

if (plugin.opts.parse) {
Internals.parse = plugin.opts.parse;
}

if (tagName.indexOf((plugin.opts.tagName || 'html')) !== 0) {
return;
}
Expand Down Expand Up @@ -235,7 +238,7 @@ export default function({ types: t }) {
}
});

const root = parse(HTML, null, { strict }).childNodes;
const root = createTree(Internals.parse(HTML, null, { strict })).childNodes;
const strRoot = JSON.stringify(root.length === 1 ? root[0] : root);
const vTree = babylon.parse('(' + strRoot + ')');

Expand Down
Loading

0 comments on commit 28b8416

Please sign in to comment.