Skip to content

Commit

Permalink
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core
Browse files Browse the repository at this point in the history
… into gh-pages
  • Loading branch information
JensLincke committed Jun 5, 2024
2 parents 32b0aa2 + e8bc8ce commit edd6144
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ export function getSourceLocation(node, state, template, t) {
fileName = 'workspace:' + fileName.split('unnamed_module_')[1];
}
if (!node.loc) {

console.error("Make sure to add loc information manually when inserting an AE or assignment while transforming" + node.left.name + " = " + node.right.name);
return t.identifier("undefined");
// console.error("Make sure to add loc information manually when inserting an AE or assignment while transforming" + node.left.name + " = " + node.right.name);
// return t.identifier("undefined");
return template(`({
file: '${fileName}',
end: { column: 0, line: 1 },
start: { column: 0, line: 1 },
source: ''
})`)({}).expression;
}
if (node.loc === "sourceless") {
return t.identifier("undefined");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let target = 0
let source = 2

target <~ 32 * source

source = 10

target
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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');
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,
}))
}
})
}
}
}
}











// 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,
// }))
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"source": "/src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings-example.js",
"sources": [
"/src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings-example.js"
],
"options": {
"systemJS": false,
"autoExecute": true,
"autoRunTests": false,
"autoUpdateAST": true,
"autoUpdateTransformation": true,
"autoSaveWorkspace": true
},
"plugin": "src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js",
"openPlugins": [
"src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js"
],
"pluginSelection": [
{
"url": "src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"sources": [
"/demos/stefan/aexpr-diss-inter-tagger-reliability/aexpr-diss-signals-aexpr-input.js"
],
"plugin": "src/external/babel-plugin-doit-result.js",
"plugin": "src/client/reactive/babel-plugin-active-expression-rewriting/index.js",
"options": {
"autoUpdateAST": true,
"autoUpdateTransformation": true,
Expand All @@ -14,10 +14,10 @@
},
"pluginSelection": [
{
"url": "src/external/babel-plugin-doit-result.js"
"url": "src/client/reactive/babel-plugin-active-expression-rewriting/index.js"
}
],
"openPlugins": [
"src/external/babel-plugin-doit-result.js"
"src/client/reactive/babel-plugin-active-expression-rewriting/index.js"
]
}
10 changes: 8 additions & 2 deletions src/components/tools/lively-plugin-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ import files from "src/client/files.js"

export default class PluginExplorer extends Morph {

static get defaultPluginURL() { return lively4url + "/src/components/tools/lively-ast-explorer-example-plugin.js"; }
static get defaultPluginURL() {
// return lively4url + "/src/components/tools/lively-ast-explorer-example-plugin.js";
return lively4url + 'src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js'
}

static get defaultWorkspacePath() { return "/src/components/tools/lively-plugin-explorer-playground.workspace"; }
static get defaultWorkspacePath() {
// return "/src/components/tools/lively-plugin-explorer-playground.workspace";
return '/src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.workspace';
}

/*MD ## UI Accessing MD*/

Expand Down
9 changes: 9 additions & 0 deletions src/plugin-babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,9 @@ async function basePlugins() {

async function livelyPlugins() {
return [
[await importDefaultOf('babel-plugin-sample-data-bindings'), {
executedIn: "file"
}],
[await importDefaultOf('babel-plugin-active-expression-rewriting'), {
executedIn: "file"
}],
Expand Down Expand Up @@ -418,6 +421,9 @@ async function aexprViaDirectivePlugins(options = {}) {
[await importDefaultOf('babel-plugin-ILA'), {
executedIn: 'file'
}],
[await importDefaultOf('babel-plugin-sample-data-bindings'), {
executedIn: 'file'
}],
[await importDefaultOf('babel-plugin-databindings'), {
executedIn: 'file'
}],
Expand Down Expand Up @@ -494,6 +500,9 @@ async function workspacePlugins(options = {}) {
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'
}])
Expand Down
1 change: 1 addition & 0 deletions src/systemjs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ System.config({
'active-expression-proxies': lively4url + '/src/client/reactive/active-expression-proxies/active-expression-proxies.js',
'babel-plugin-active-expression-rewriting': lively4url + '/src/client/reactive/babel-plugin-active-expression-rewriting/index.js',
'babel-plugin-ILA': lively4url + '/src/client/reactive/babel-plugin-ILA/index.js',
'babel-plugin-sample-data-bindings': lively4url + '/src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js',
'babel-plugin-databindings': lively4url + '/src/client/reactive/babel-plugin-databindings/index.js',
'babel-plugin-databindings-post-process': lively4url + '/src/client/reactive/babel-plugin-databindings/post-process.js',
'babel-plugin-active-expression-proxies': lively4url + '/src/client/reactive/babel-plugin-active-expression-proxies/index.js',
Expand Down

0 comments on commit edd6144

Please sign in to comment.