Atom Expression Compiler
raw JSON → 2.2.4 verified Fri May 01 auth: no javascript
A Vue expression compiler for server-side rendering (SSR) that pre-compiles Vue template expressions into executable JavaScript functions. Version 2.2.4 supports modern Vue 3 syntax and provides faster runtime evaluation compared to traditional string-based evaluation. It handles interpolation, filters, and complex expressions with proper scoping. The package is lightweight, has no runtime dependencies, and is designed specifically for SSR optimization in Vue applications. It is actively maintained with monthly releases.
Common errors
error Cannot find module 'atom-expression-compiler' ↓
cause Package not installed or incorrect import path.
fix
Run 'npm install atom-expression-compiler' and ensure import path is correct.
error 'require' is not defined in ES module scope ↓
cause Using require() with ESM-only version.
fix
Use import statement or downgrade to version 1.x.
error TypeError: compiler is not a function ↓
cause Default import used for a named export.
fix
Use named import: import { compileExpression } from 'atom-expression-compiler'.
error Unexpected token 'export' ↓
cause Running code in a CommonJS environment without ESM support.
fix
Enable ESM in package.json ("type": "module") or use bundler.
Warnings
breaking Requirement for ESM imports only; CommonJS require throws error. ↓
fix Use ES module imports (import syntax) instead of require(). If using CommonJS, stick with version 1.x.
deprecated The 'sourceMap' option is deprecated and will be removed in v3. ↓
fix Remove 'sourceMap' option from compile call; it is now always false.
gotcha Compiled functions rely on global _ctx variable; ensure context is passed correctly. ↓
fix Wrap compiled code with proper scope passing _ctx, e.g., using Function.prototype.call.
breaking Return type changed from string to object in v2. ↓
fix Access compiled code via .code property instead of directly using the returned value.
Install
npm install atom-expression-compiler yarn add atom-expression-compiler pnpm add atom-expression-compiler Imports
- compileExpression wrong
const { compileExpression } = require('atom-expression-compiler')correctimport { compileExpression } from 'atom-expression-compiler' - CompileResult
import type { CompileResult } from 'atom-expression-compiler' - default wrong
import { default as compiler } from 'atom-expression-compiler'correctimport compiler from 'atom-expression-compiler'
Quickstart
import { compileExpression } from 'atom-expression-compiler';
const expr = 'name + " - " + age';
const code = compileExpression(expr, {
compact: true,
sourceMap: false
});
console.log(code);
// Output: function anonymous($event,_ctx,_c,_ssrAttr) { return _ctx.name + ' - ' + _ctx.age }