From 0886187a43e6c00bba97d9c5fe71aaea4c78ee20 Mon Sep 17 00:00:00 2001 From: onsetsu Date: Thu, 4 Jul 2024 16:27:26 +0200 Subject: [PATCH] ubg notes SQUASHED: ubg-notes, --- .../aexpr-diss-check-ast-nodes/README.md | 57 +++++++++++ .../aexpr-diss-check-ast-nodes/results.md | 69 +++++++++++++ .../sample-data-bindings.js | 97 +++++++++---------- .../scribbles.js | 12 +++ src/components/widgets/ubg-cards-entry.js | 26 +---- src/components/widgets/ubg-cards.html | 2 +- src/components/widgets/ubg-cards.js | 27 +++++- src/plugin-babel.js | 14 +-- 8 files changed, 219 insertions(+), 85 deletions(-) create mode 100644 demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/README.md create mode 100644 demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/results.md create mode 100644 src/client/reactive/babel-plugin-sample-data-bindings/scribbles.js diff --git a/demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/README.md b/demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/README.md new file mode 100644 index 000000000..735781d60 --- /dev/null +++ b/demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/README.md @@ -0,0 +1,57 @@ +# Number of AST Nodes + + + \ No newline at end of file diff --git a/demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/results.md b/demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/results.md new file mode 100644 index 000000000..f6313f8b5 --- /dev/null +++ b/demos/stefan/active-expressions/aexpr-diss-check-ast-nodes/results.md @@ -0,0 +1,69 @@ +# Convention +- ast nodes 136 = 18 + 118 +- sloc (29) = (1) + (28) + +[aexpr-ticking](https://github.com/active-expressions/aexpr-ticking.git) +e9b4034 +e9b4034606dd286ac494f20293cf7e7e9649e0ac + +- https://lively-kernel.org/lively4/aexpr/../aexpr-ticking/src/./aexpr-ticking.js 18 (1) +- https://lively-kernel.org/lively4/aexpr/../aexpr-ticking/src/./ticking/ticking-active-expressions.js 118 (28) + +# Interpretation +- ast nodes 787 = 12+182+224+369 +- sloc (170) = (1)+(43)+(51)+(75) + +[aexpr-interpretation](https://github.com/active-expressions/aexpr-interpretation.git) +46d1d17 +46d1d175b4cb040bda636fe871ef5d2f70f5e3e8 + +- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./aexpr-interpretation.js 12 (1) +- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/property-accessor.js 182 (43) +- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/listener.js 224 (51) +- https://lively-kernel.org/lively4/aexpr/../aexpr-interpretation/src/./interpretation/interpretation-active-expressions.js 369 (75) + +# Compilation +- ast nodes 2281 = 730+1551 +- sloc (471) = (169)+(302) + +[aexpr-source-transformation-propagation](https://github.com/active-expressions/aexpr-source-transformation-propagation.git) +3154d05 +3154d05af0ce410b041eb312ba57f7d32a6e7672 + +- https://lively-kernel.org/lively4/aexpr/../aexpr-source-transformation-propagation/src/./aexpr-source-transformation-propagation.js 730 (169) + +[babel-plugin-aexpr-source-transformation](https://github.com/active-expressions/babel-plugin-aexpr-source-transformation.git) +54a712a +54a712a45175f98c0f0a627770ae811759b195da + +- https://lively-kernel.org/lively4/aexpr/../babel-plugin-aexpr-source-transformation/./index.js 1551 (302) + +--- + +--- + +2820 + null + +all ref + 5794 = 1707 + 1267 + 2820 + +all aexpr + 3038 = 274 + 672 + 2092 + +interpret aexpr + 926 = 787 + 139 + +sum aexprs + 3964 = 3038 + 926 + +1707 - 274 +1267 - 672 +2820 - 2092 + +subsec:impl_comparison + subsec:impl_complexity + subsec:impl_qualitative_analysis + subsec:impl_quantitative_analysis + + +3018 = 2092 + 787 + 139 diff --git a/src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js b/src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js index 31ef596f9..ad5b10619 100644 --- a/src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js +++ b/src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js @@ -1,56 +1,23 @@ -console.log(123) export default function ({ template, types: t }) { return { name: 'sample data bindings (<~)', visitor: { Program(program) { // handle squiggly arrow operator - function leftRightOfSquigglyArrow(path) { - if (!path.isBinaryExpression()) { return [] } - if (path.node.operator !== '<') { return [] } - - let right - const expression = path.get('right') - if (expression.isUnaryExpression() && expression.node.operator === '~') { - right = expression.get('argument') - } else { - expression.traverse({ - UnaryExpression(unary) { - if (unary.node.operator !== '~') { return } - if (expression.node.loc.start.index !== unary.node.loc.start.index) { return } - unary.stop() - unary.replaceWith(unary.get('argument').node) - right = expression - } - }) - } - debugger - if (!right) { return [] } - - const left = path.get('left') - if (!left.isLVal()) { - throw left.buildCodeFrameError("Unassignable left-hand side of data binding") - } - - return [left, right] - } - program.traverse({ - ExpressionStatement(expressionStatementPath) { - const path = expressionStatementPath.get('expression'); + ExpressionStatement(stmt) { + const path = stmt.get('expression'); const [left, right] = leftRightOfSquigglyArrow(path); - if (!left || !right) { - // path.replaceWith(t.numberLiteral(123)) - return - } - - const valueName = right.scope.generateUidIdentifier('value') - const bindingTemplate = template(`aexpr(() => EXPRESSION) -.dataflow(${valueName.name} => REFERENCE = ${valueName.name})`) - path.replaceWith(bindingTemplate({ - REFERENCE: left.node, - EXPRESSION: right.node, - })) + if (!left || !right) { return } + + // path.replaceWith(t.numberLiteral(123)) + + // const name = path.scope.generateUidIdentifier('value').name; + // const db = template(`ae(EXPR).onChange(${name} => REF = ${name})`)({ + // EXPR: right, + // REF: left + // }); + // path.replaceWith(db) } }) } @@ -59,7 +26,35 @@ export default function ({ template, types: t }) { } +function leftRightOfSquigglyArrow(path) { + if (!path.isBinaryExpression()) { return [] } + if (path.node.operator !== '<') { return [] } + + let right + const expression = path.get('right') + if (expression.isUnaryExpression() && expression.node.operator === '~') { + right = expression.get('argument') + } else { + expression.traverse({ + UnaryExpression(unary) { + if (unary.node.operator !== '~') { return } + if (expression.node.loc.start.index !== unary.node.loc.start.index) { return } + unary.stop() + unary.replaceWith(unary.get('argument').node) + right = expression + } + }) + } + if (!right) { return [] } + + const left = path.get('left') + if (!left.isLVal()) { + throw left.buildCodeFrameError("Unassignable left-hand side of data binding") + } + console.warn('squiggly arrow found') + return [left.node, right.node] +} @@ -68,10 +63,8 @@ export default function ({ template, types: t }) { -// const valueName = right.scope.generateUidIdentifier('value') -// const bindingTemplate = template(`aexpr(() => EXPRESSION) -// .dataflow(${valueName.name} => REFERENCE = ${valueName.name})`) -// path.replaceWith(bindingTemplate({ -// REFERENCE: left.node, -// EXPRESSION: right.node, -// })) + // const db = template(`aexpr(() => SOURCE).dataflow(v => TARGET = v)`)({ + // SOURCE: right, + // TARGET: left, + // }); + // path.replaceWith(db) \ No newline at end of file diff --git a/src/client/reactive/babel-plugin-sample-data-bindings/scribbles.js b/src/client/reactive/babel-plugin-sample-data-bindings/scribbles.js new file mode 100644 index 000000000..50c7aee27 --- /dev/null +++ b/src/client/reactive/babel-plugin-sample-data-bindings/scribbles.js @@ -0,0 +1,12 @@ +const target = document.getElementById('target'); + +target.style.width <~ that.style.width + + + + + + +ae(that.style.width).onChange(v => target.style.width = v) +import { AExprRegistry } from 'src/client/reactive/active-expression/ae-registry.js' +AExprRegistry.allAsArray().last.dispose() \ No newline at end of file diff --git a/src/components/widgets/ubg-cards-entry.js b/src/components/widgets/ubg-cards-entry.js index 0431b62cc..ef84d3454 100644 --- a/src/components/widgets/ubg-cards-entry.js +++ b/src/components/widgets/ubg-cards-entry.js @@ -112,30 +112,8 @@ export default class UBGCardEntry extends Morph { this.classList.toggle('out-of-range', !inRange); } - updateToFilter(filter) { - let matching - - if (filter.startsWith('>')) { - let functionBody = 'return ' + filter.substring(1).trim(); - let filterFunction = new Function('c', functionBody); - matching = !!filterFunction(this.card) - } else { - filter = filter.toLowerCase(); - - const card = this.card; - const id = card.getId(); - const name = card.getName(); - const cardType = card.getType() - const element = card.getElement(); - const cost = card.getCost(); - const text = card.getText(); - const notes = card.getNotes(); - const tags = card.getTags().join(' '); - const aspects = [id, name, cardType, element, cost, text, notes, tags]; - - matching = aspects.some(aspect => (aspect + '').toLowerCase().match(new RegExp(filter, 'gmi'))); - } - + updateToFilter(filterFunction) { + const matching = filterFunction(this.card) this.classList.toggle('match', matching); this.classList.toggle('hidden', !matching); } diff --git a/src/components/widgets/ubg-cards.html b/src/components/widgets/ubg-cards.html index c89330ecc..c201836e4 100644 --- a/src/components/widgets/ubg-cards.html +++ b/src/components/widgets/ubg-cards.html @@ -126,7 +126,7 @@
- + diff --git a/src/components/widgets/ubg-cards.js b/src/components/widgets/ubg-cards.js index 3053f7c69..fed6d8776 100644 --- a/src/components/widgets/ubg-cards.js +++ b/src/components/widgets/ubg-cards.js @@ -699,10 +699,35 @@ export default class Cards extends Morph { }); } + functionForFilter(filter) { + if (filter.startsWith('>')) { + let functionBody = `return !!(${filter.substring(1).trim()})`; + return new Function('c', functionBody); + } + + filter = filter.toLowerCase(); + const regex = new RegExp(filter, 'gmi') + + return function filterFunction(card) { + const id = card.getId(); + const name = card.getName(); + const cardType = card.getType() + const element = card.getElement(); + const cost = card.getCost(); + const text = card.getText(); + const notes = card.getNotes(); + const tags = card.getTags().join(' '); + + const aspects = [id, name, cardType, element, cost, text, notes, tags]; + return aspects.some(aspect => (aspect + '').toLowerCase().match(regex)); + } + } + updateItemsToFilter() { const filterValue = this.filterValue; + const filterFunction = this.functionForFilter(filterValue); this.allEntries.forEach(entry => { - entry.updateToFilter(filterValue); + entry.updateToFilter(filterFunction); }); } diff --git a/src/plugin-babel.js b/src/plugin-babel.js index 969e611ce..098681e77 100644 --- a/src/plugin-babel.js +++ b/src/plugin-babel.js @@ -417,13 +417,11 @@ async function aexprViaDirectivePlugins(options = {}) { await importDefaultOf('babel-plugin-syntax-async-generators'), await importDefaultOf('babel-plugin-syntax-object-rest-spread'), await importDefaultOf('babel-plugin-syntax-class-properties'), + await importDefaultOf('babel-plugin-sample-data-bindings'), await importDefaultOf('babel-plugin-var-recorder'), [await importDefaultOf('babel-plugin-ILA'), { executedIn: 'file' }], - [await importDefaultOf('babel-plugin-sample-data-bindings'), { - executedIn: 'file' - }], [await importDefaultOf('babel-plugin-databindings'), { executedIn: 'file' }], @@ -492,17 +490,19 @@ async function workspacePlugins(options = {}) { ]) + const enableAExprsInWorkspace = localStorage.getItem("DisableAExpWorkspace") !== "true"; + if (enableAExprsInWorkspace) { + result.push(await importDefaultOf('babel-plugin-sample-data-bindings')) + } + result.push(...await doitPlugins()) result.push(await importDefaultOf('babel-plugin-var-recorder')) - if (localStorage.getItem("DisableAExpWorkspace") !== "true") { + if (enableAExprsInWorkspace) { result.push([await importDefaultOf('babel-plugin-ILA'), { executedIn: 'file' }]) - result.push([await importDefaultOf('babel-plugin-sample-data-bindings'), { - executedIn: 'file' - }]) result.push([await importDefaultOf('babel-plugin-databindings'), { executedIn: 'file' }])