Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed Jan 13, 2024
1 parent 479979f commit 2a123a2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"prettier.enable": true,
"editor.maxTokenizationLineLength": 100000,
"[glimmer-js]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
Expand Down
6 changes: 4 additions & 2 deletions plugins/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function convert(seenNodes: Set<ASTv1.Node>) {
}
return ToJSType(node.path);
} else {
return `${wrap ? `$:() => ` : ''}${ToJSType(node.path)}(${node.params
return `${wrap ? `$:() => ` : ''}${SYMBOLS.$_maybeHelper}(${ToJSType(node.path)})(${node.params
.map((p) => ToJSType(p))
.map((el) => {
if (typeof el !== 'string') {
Expand Down Expand Up @@ -225,7 +225,7 @@ export function convert(seenNodes: Set<ASTv1.Node>) {
let isNull = p.type === 'NullLiteral';
let isUndefined = p.type === 'UndefinedLiteral';
let originalName = node.program.blockParams[index];
let newName = `${originalName}_${varScopeName}`;
let newName = `S${originalName}_${varScopeName}`;
namesToReplace[originalName] = `${newName}`;
if (
isSubExpression ||
Expand Down Expand Up @@ -259,6 +259,8 @@ export function convert(seenNodes: Set<ASTv1.Node>) {
children as unknown as [string | HBSNode | HBSControlExpression],
'this', // @todo - fix possible context floating here
))}]})()`;
// console.log(namesToReplace);
// console.log(result);
return result;
}

Expand Down
6 changes: 4 additions & 2 deletions plugins/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export function isPath(str: string) {
}

export function resolvePath(str: string) {
return str.replace('$:', '').replace('@', `this[${SYMBOLS.$args}].`);
const p = str.replace('$:', '').replace('@', `this[${SYMBOLS.$args}].`);
return p;
// return `${SYMBOLS.$_maybeHelper}(${p})`;
}

export function serializePath(
Expand All @@ -68,7 +70,7 @@ export function serializePath(
}

export function resolvedChildren(els: ASTv1.Node[]) {
if (els.length === 1 && els[0].type === 'BlockStatement') {
if (els.length === 1 && els[0].type === 'BlockStatement' && els[0].path.type === 'PathExpression' && els[0].path.original === 'if') {
// hack for 'else if' // @todo write proper nesting
return resolvedChildren((els[0] as ASTv1.BlockStatement).program.body);
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ function $attr(
}

export function $_maybeHelper(value: any) {
if (isPrimitive(value)) {
return value;
}
if (value.prototype && value.prototype.compute) {
const helper = new value();
return (...args: any[]) => {
Expand Down

0 comments on commit 2a123a2

Please sign in to comment.