Skip to content

Commit

Permalink
codegen: tagged template literals
Browse files Browse the repository at this point in the history
test262: 41.98% (+0.03) | πŸ§ͺ 48414 | 🀠 20323 (+15) | ❌ 6509 (+8) | πŸ’€ 15375 (+21) | πŸ—οΈ 64 | πŸ’₯ 301 | ⏰ 28 | πŸ“ 5814 (-44)
  • Loading branch information
CanadaHonk committed Aug 31, 2024
1 parent dbe67bc commit 62a78ae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
17 changes: 15 additions & 2 deletions compiler/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5885,8 +5885,8 @@ const generateTaggedTemplate = (scope, decl, global = false, name = undefined) =
__Porffor_s: str => makeString(scope, str, global, name, false)
};

const { quasis, expressions } = decl.quasi;
if (intrinsics[decl.tag.name]) {
const { quasis, expressions } = decl.quasi;
let str = quasis[0].value.raw;

for (let i = 0; i < expressions.length; i++) {
Expand All @@ -5903,7 +5903,20 @@ const generateTaggedTemplate = (scope, decl, global = false, name = undefined) =
return cacheAst(decl, intrinsics[decl.tag.name](str));
}

return todo(scope, 'tagged template expressions not implemented', true);
return generate(scope, {
type: 'CallExpression',
callee: decl.tag,
arguments: [
{ // strings
type: 'ArrayExpression',
elements: quasis.map(x => ({
type: 'Literal',
value: x.value.cooked
}))
},
...expressions
]
});
};

globalThis._uniqId = 0;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "porffor",
"description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
"version": "0.41.3+da80ef2f5",
"version": "0.41.4+e41715a96",
"author": "CanadaHonk",
"license": "MIT",
"scripts": {},
Expand Down
2 changes: 1 addition & 1 deletion runner/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import fs from 'node:fs';
globalThis.version = '0.41.3+da80ef2f5';
globalThis.version = '0.41.4+e41715a96';

// deno compat
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion test262/history.json

Large diffs are not rendered by default.

0 comments on commit 62a78ae

Please sign in to comment.