-
Notifications
You must be signed in to change notification settings - Fork 16
Serialize compiled function as module #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request implements a new method of serializing compiled templates as an ES module to allow usage in environments where dynamic function generation is forbidden. Key changes include:
- Removing the legacy helper function and updating tests to reference the compiled function via its new 'compiled' property.
- Adding a suite of tests in serializer.test.js that cover various template scenarios, including nested IDs, meta comments, and include/wrapper functionality.
- Updating the serializer and micro-template modules to correctly export and attach properties on compiled functions.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/test.js | Updated template function invocation and test for source maps. |
| test/serializer.test.js | Added comprehensive tests for the new serialization module. |
| test/serialize/*.tmpl | New template files demonstrating meta keys and template composition. |
| package.json | Updated with new bin and exports configuration. |
| lib/serializer.js | Implements serialization of compiled templates to an ES module. |
| lib/micro-template.js | Adjusted function compilation and property attachment. |
| index.html | Updated documentation section for getting started. |
Comments suppressed due to low confidence (1)
test/test.js:321
- [nitpick] The variable name 'func' is ambiguous; consider renaming it to a more descriptive name like 'compiledTemplate' for clarity.
const func = template('foo bar', []);
|
|
||
| for (const [id, entry] of Object.entries(target)) { | ||
| const keys = entry.keys || []; | ||
| console.log(`Compiling template: ${id}`); |
Copilot
AI
Jun 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider removing or gating the console.log statement to avoid unwanted logging in production builds.
| console.log(`Compiling template: ${id}`); | |
| if (process.env.NODE_ENV !== 'production') { | |
| console.log(`Compiling template: ${id}`); | |
| } |
new Function が許されない環境向けに module としてコードを直接生成するサンプルを試行錯誤中
usage
以下で test/serialize/*.tmpl をコンパイルし、_serialized.js に esm として出力
以下のように import して使える。(実行時には動的関数生成が走らない)
問題点
と指定するようにした
非互換