Skip to content

Commit

Permalink
trying to run ember-eui
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed Jan 15, 2024
1 parent 08aed4e commit 3890d0b
Show file tree
Hide file tree
Showing 38 changed files with 4,044 additions and 148 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
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<link rel="stylesheet" href="/src/style.css" />
</head>
<body>
<script>
window.global = window;
</script>
<div id="app"><!--ssr-outlet--></div>
<script type="module">
import App from "/src/index.ts";
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
}
},
"devDependencies": {
"@ember-eui/core": "^8.0.4",
"@glint/core": "^1.2.1",
"@glint/environment-ember-template-imports": "^1.2.1",
"@glint/environment-glimmerx": "^1.2.1",
Expand Down Expand Up @@ -89,11 +90,15 @@
"vitest": "^1.1.1",
"zx": "^7.2.3",
"express": "^4.18.2",
"happy-dom": "^13.0.6"
"happy-dom": "^13.0.6",
"@babel/standalone": "^7.23.8",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@babel/plugin-syntax-decorators": "^7.23.3",
"@babel/preset-typescript": "^7.23.3",
"@babel/core": "^7.23.6",
"babel-import-util": "^2.0.1"
},
"dependencies": {
"@babel/core": "^7.23.6",
"@babel/preset-typescript": "^7.23.3",
"@glimmer/syntax": "^0.87.1",
"content-tag": "^1.2.2"
}
Expand Down
21 changes: 20 additions & 1 deletion plugins/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ export function processTemplate(
);
}
},
CallExpression(path: any) {
// @ts-expect-error context is not used
CallExpression(path: any, context: Context) {
if (path.node.callee && path.node.callee.type === 'Identifier') {
if (path.node.callee.name === 'scope') {
path.remove();
Expand All @@ -111,6 +112,24 @@ export function processTemplate(
path.node.arguments.pop();
}
}
} else if (path.node.callee.name === 'precompileTemplate') {
// const template = path.node.arguments[0].quasis[0].value
// .raw as string;
// const isInsideClassBody = context.isInsideClassBody === true;
// const hasThisInTemplate = template.includes('this');
// let hasThisAccess =
// isInsideClassBody === true || hasThisInTemplate;
// // looks like it's function based template, we don't need to mess with it's context hell
// if (context.isInsideReturnStatement === true) {
// hasThisAccess = true;
// }
// hbsToProcess.push({
// template,
// flags: {
// hasThisAccess: hasThisAccess,
// },
// });
// path.replaceWith(t.identifier('$placeholder'));
}
}
},
Expand Down
13 changes: 9 additions & 4 deletions plugins/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Plugin } from 'vite';
import { Preprocessor } from 'content-tag';
import { transform } from './test';
import { MAIN_IMPORT } from './symbols';
// import { MAIN_IMPORT } from './symbols';
import { flags } from './flags.ts';
import { HMR, fixExportsForHMR, shouldHotReloadFile } from './hmr.ts';

Expand All @@ -22,6 +22,8 @@ export function compiler(mode: string): Plugin {
if (!isLibBuild) {
defineValues['IS_DEV_MODE'] = mode.mode === 'development';
}
defineValues['process.env.BABEL_TYPES_8_BREAKING'] = false;

return {
define: defineValues,
};
Expand All @@ -48,12 +50,15 @@ export function compiler(mode: string): Plugin {
);
}
}
if (!code.includes(MAIN_IMPORT)) {
return;
}
// if (!code.includes(MAIN_IMPORT)) {
// return;
// }
let result: string | undefined = undefined;
if (ext === 'ts' || ext === 'js') {
const source = code;
// if (code.includes('precompileTemplate')) {
// console.log(code);
// }
const result = transform(
source,
file,
Expand Down
39 changes: 25 additions & 14 deletions plugins/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function convert(seenNodes: Set<ASTv1.Node>) {
);
return `$:${node.path.original}(${toObject(hashArgs)})`;
}
return `$:${node.path.original}(${node.params
return `$:${SYMBOLS.$_maybeHelper}(${node.path.original})(${node.params
.map((p) => ToJSType(p))
.join(',')})`;
} else if (node.type === 'NumberLiteral') {
Expand Down Expand Up @@ -157,7 +157,9 @@ 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 @@ -216,37 +218,46 @@ export function convert(seenNodes: Set<ASTv1.Node>) {
key: keyValue,
} as HBSControlExpression;
} else if (name === 'let') {
const varScopeName = Math.random().toString(36).substring(7);
const namesToReplace: Record<string, string> = {};
const vars = node.params.map((p, index) => {
let isSubExpression = p.type === 'SubExpression';
let isString = p.type === 'StringLiteral';
let isBoolean = p.type === 'BooleanLiteral';
let isNull = p.type === 'NullLiteral';
let isUndefined = p.type === 'UndefinedLiteral';
let originalName = node.program.blockParams[index];
let newName = `S${originalName}_${varScopeName}`;
namesToReplace[originalName] = `${newName}`;
if (
isSubExpression ||
isString ||
isBoolean ||
isNull ||
isUndefined
) {
return `let ${node.program.blockParams[index]} = ${ToJSType(
p,
false,
)};`;
return `let ${newName} = ${ToJSType(p, false)};`;
} else {
return `let ${node.program.blockParams[index]} = $:() => ${ToJSType(
p,
)};`;
return `let ${newName} = $:() => ${ToJSType(p)};`;
}
});
// note, at the moment nested let's works fine if no name overlap,
// looks like fix for other case should be on babel level;
const result = `$:...(() => {${vars.join(
'',
)}return [${serializeChildren(
children as unknown as [string | HBSNode | HBSControlExpression],
'this', // @todo - fix possible context floating here
// @todo - likely should be a babel work
function fixChildScopes(str: string) {
Object.keys(namesToReplace).forEach((key) => {
str = str.split(key).join(namesToReplace[key]);
});
return str;
}
const result = `$:...(() => {${vars.join('')}return [${fixChildScopes(
serializeChildren(
children as unknown as [string | HBSNode | HBSControlExpression],
'this', // @todo - fix possible context floating here
),
)}]})()`;
// console.log(namesToReplace);
// console.log(result);
return result;
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/decorator-transforms/globals.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as runtime from './runtime.ts';
(globalThis as any)['dt7948'] = runtime;
Loading

0 comments on commit 3890d0b

Please sign in to comment.