Skip to content

Commit

Permalink
0.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed Dec 10, 2023
1 parent c51410b commit cf0e764
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 18 deletions.
41 changes: 34 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,17 @@ Value coming from marker
...

<script nomodule>
{
({
prop1: isHappy && !isWealthy && liberated.length > 17,
prop2: liberated.blink()
}
})
</script>
<any-element itemprop=isInNirvana be-computed='from previous script element, passing in $isHappy, @isWealthy, #liberated, then assign result to $0.'></any-element>
<any-element itemprop=isInNirvana be-computed='from previous script element, passing in $isHappy, @isWealthy, #liberated, and assign result.'></any-element>
</form>
```

Detecting such expressions: Starts and ends with ({...}), no arrow. If need to use arrow functions inside, need to provide the context.

## Example 2b Assigning objects, compact notation, external script [TODO]

```html
Expand All @@ -257,7 +259,7 @@ Value coming from marker
prop2: liberated.blink()
}
</script>
<any-element itemprop=isInNirvana be-computed='from $isHappy, @isWealthy, #liberated, then assign result to $0.'></any-element>
<any-element itemprop=isInNirvana be-computed='from $isHappy, @isWealthy, #liberated, and assign result.'></any-element>
</form>
```

Expand All @@ -277,7 +279,7 @@ Value coming from marker
prop2: liberated.blink()
}
"
be-computed='from onload expression, passing in $isHappy, @isWealthy, #liberated, then assign result to $0.'></any-element>
be-computed='from onload expression, passing in $isHappy, @isWealthy, #liberated, and assign result.'></any-element>
</form>
```

Expand All @@ -296,7 +298,8 @@ Value coming from marker
prop2: liberated.blink()
}
"
be-computed='from $isHappy, @isWealthy, #liberated, assigning result to $0.'></any-element>
be-computed='from $isHappy, @isWealthy, #liberated, and assign result.'>
</any-element>
</form>
```

Expand All @@ -312,7 +315,31 @@ Value coming from marker

<div
onload="{isInNirvana: isHappy && isWealthy}"
be-computed='from onload expression, passing in $isHappy, $isWealthy, followed by data-xform transform.'
be-computed='from onload expression, passing in $isHappy, $isWealthy, and do data-xform transform.'
data-xform='{
"span": "isInNirvana"
}'
>
<span></span>
</div>
</div>
```

Uses DTR syntax (enhanced by be-linked for things like html signals, etc).

## Example 3b Support for inner transform, compact notation [TODO]


```html
<div itemscope>
<link itemprop=isHappy href=https://schema.org/True>
<link itemprop=isWealthy href=https://schema.org/False>

...

<div
onload="{isInNirvana: isHappy && isWealthy}"
be-computed='from $isHappy, $isWealthy, with xform.'
data-xform='{
"span": "isInNirvana"
}'
Expand Down
11 changes: 7 additions & 4 deletions demo/Example2a.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example 2a</title>
<title>Example 1a</title>
<script type=importmap>
{
"imports": {
Expand All @@ -22,19 +22,22 @@
</head>
<body>
<form itemscope>
<link itemprop=isHappy href=https://schema.org/True>
<input type=checkbox name=isWealthy>
<div contenteditable id=liberated>abc</div>
...

<script nomodule>
({
numValue: liberated.length
prop1: isHappy && !isWealthy && liberated.length > 17,
prop2: liberated.blink()
})
</script>
<my-custom-element be-computed='from #liberated.'></my-custom-element>
<any-element itemprop=isInNirvana enh-by-be-computed='from previous script element expression, passing in $isHappy, @isWealthy, #liberated, and assign result.'></any-element>
</form>
<script type=module>
import '../be-computed.js';
import '../my-custom-element/my-custom-element.js';
import '../any-element/any-element.js';
</script>
</body>
</html>
10 changes: 9 additions & 1 deletion prsFrom.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { tryParse } from 'be-enhanced/cpu.js';
import { lispToCamel } from 'trans-render/lib/lispToCamel.js';
const previousScriptElementExpression = String.raw `(?<!\\)previousScriptElementExpression`;
const reValueStatement = [
{
regExp: new RegExp(String.raw `^(?<!\\)previousScriptElementExpression,PassingIn(?<dependencies>.*)`),
regExp: new RegExp(String.raw `^${previousScriptElementExpression},PassingIn(?<dependencies>.*),AndAssignResult`),
defaultVals: {
previousElementScriptElement: true,
assignResult: true
}
},
{
regExp: new RegExp(String.raw `^${previousScriptElementExpression},PassingIn(?<dependencies>.*)`),
defaultVals: { previousElementScriptElement: true }
},
{
Expand Down
10 changes: 9 additions & 1 deletion prsFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import {RegExpOrRegExpExt} from 'be-enhanced/types';
import {arr, tryParse} from 'be-enhanced/cpu.js';
import {lispToCamel} from 'trans-render/lib/lispToCamel.js';

const previousScriptElementExpression = String.raw `(?<!\\)previousScriptElementExpression`;
const reValueStatement: RegExpOrRegExpExt<ComputeStatement>[] = [
{
regExp: new RegExp(String.raw `^(?<!\\)previousScriptElementExpression,PassingIn(?<dependencies>.*)`),
regExp: new RegExp(String.raw `^${previousScriptElementExpression},PassingIn(?<dependencies>.*),AndAssignResult`),
defaultVals:{
previousElementScriptElement: true,
assignResult: true
}
},
{
regExp: new RegExp(String.raw `^${previousScriptElementExpression},PassingIn(?<dependencies>.*)`),
defaultVals:{previousElementScriptElement: true}
},
{
Expand Down
10 changes: 8 additions & 2 deletions rewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ export function rewrite(script, names) {
return trimmedScript;
}
if (trimmedScript[0] === '(') {
const newScript2 = `export const expr = async ${trimmedScript}`;
return newScript2;
if (trimmedScript.startsWith('({') && trimmedScript.endsWith('})') && !trimmedScript.includes('=>')) {
const newScript1 = `export const expr = async ({${names.join(', ')}}) =>${trimmedScript}`;
return newScript1;
}
else {
const newScript2 = `export const expr = async ${trimmedScript}`;
return newScript2;
}
}
const newScript3 = `
export const expr = async ({${names.join(', ')}}) => {
Expand Down
10 changes: 8 additions & 2 deletions rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ export function rewrite(script: string, names: Array<string>): string{
return trimmedScript;
}
if(trimmedScript[0] === '('){
const newScript2 = `export const expr = async ${trimmedScript}`;
return newScript2;
if(trimmedScript.startsWith('({') && trimmedScript.endsWith('})') && !trimmedScript.includes('=>')){
const newScript1 = `export const expr = async ({${names.join(', ')}}) =>${trimmedScript}`;
return newScript1;
}else{
const newScript2 = `export const expr = async ${trimmedScript}`;
return newScript2;
}

}
const newScript3 = `
export const expr = async ({${names.join(', ')}}) => {
Expand Down
3 changes: 2 additions & 1 deletion types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export interface ComputeStatement{
previousElementScriptElement?: boolean,
onloadOrPreviousElementScriptElement?: boolean,
dependencies?: string,
args?: Array<Arg>
args?: Array<Arg>,
assignResult?: boolean,
}

0 comments on commit cf0e764

Please sign in to comment.