-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core…
… into gh-pages
- Loading branch information
Showing
8 changed files
with
137 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings-example.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
77 changes: 77 additions & 0 deletions
77
src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
// })) |
23 changes: 23 additions & 0 deletions
23
src/client/reactive/babel-plugin-sample-data-bindings/sample-data-bindings.workspace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters