From 2a123a228aed3fc60da06069c8a2b285687d38af Mon Sep 17 00:00:00 2001 From: Alex Kanunnikov Date: Sat, 13 Jan 2024 14:15:49 +0300 Subject: [PATCH] + --- .vscode/settings.json | 1 + plugins/converter.ts | 6 ++++-- plugins/utils.ts | 6 ++++-- src/utils/dom.ts | 3 +++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index cd016260..e19eee61 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "prettier.enable": true, + "editor.maxTokenizationLineLength": 100000, "[glimmer-js]": { "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" diff --git a/plugins/converter.ts b/plugins/converter.ts index 6211ccbc..2123b389 100644 --- a/plugins/converter.ts +++ b/plugins/converter.ts @@ -157,7 +157,7 @@ export function convert(seenNodes: Set) { } 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') { @@ -225,7 +225,7 @@ export function convert(seenNodes: Set) { 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 || @@ -259,6 +259,8 @@ export function convert(seenNodes: Set) { children as unknown as [string | HBSNode | HBSControlExpression], 'this', // @todo - fix possible context floating here ))}]})()`; + // console.log(namesToReplace); + // console.log(result); return result; } diff --git a/plugins/utils.ts b/plugins/utils.ts index b566791f..21c0e5b9 100644 --- a/plugins/utils.ts +++ b/plugins/utils.ts @@ -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( @@ -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); } diff --git a/src/utils/dom.ts b/src/utils/dom.ts index d19930e7..9afc45ee 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -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[]) => {