Socket
Socket
Sign inDemoInstall

edge.js

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

edge.js - npm Package Compare versions

Comparing version 3.4.0 to 3.5.0

6

build/src/Compiler/index.d.ts

@@ -5,3 +5,3 @@ import { Parser } from 'edge-parser';

import { CacheManager } from '../CacheManager';
import { LoaderContract, TagsContract, LoaderTemplate, CompilerContract } from '../Contracts';
import { LoaderContract, TagsContract, LoaderTemplate, CompilerContract, CompilerOptions } from '../Contracts';
/**

@@ -15,5 +15,5 @@ * Compiler is to used to compile templates using the `edge-parser`. Along with that

private processor;
private cache;
private options;
cacheManager: CacheManager;
constructor(loader: LoaderContract, tags: TagsContract, processor: Processor, cache?: boolean);
constructor(loader: LoaderContract, tags: TagsContract, processor: Processor, options?: CompilerOptions);
/**

@@ -20,0 +20,0 @@ * Merges sections of base template and parent template tokens

@@ -21,8 +21,10 @@ "use strict";

class Compiler {
constructor(loader, tags, processor, cache = true) {
constructor(loader, tags, processor, options = {
cache: true,
}) {
this.loader = loader;
this.tags = tags;
this.processor = processor;
this.cache = cache;
this.cacheManager = new CacheManager_1.CacheManager(this.cache);
this.options = options;
this.cacheManager = new CacheManager_1.CacheManager(!!this.options.cache);
}

@@ -112,3 +114,3 @@ /**

templateContentToTokens(content, parser, absPath) {
let templateTokens = parser.tokenize(content, absPath, (line) => this.processor.executeLine(line));
let templateTokens = parser.tokenize(content, { filename: absPath });
const firstToken = templateTokens[0];

@@ -162,3 +164,6 @@ /**

}
const parser = new edge_parser_1.Parser(this.tags);
const parser = new edge_parser_1.Parser(this.tags, undefined, {
claimTag: this.options.claimTag,
onTag: (tag) => this.processor.executeTag({ tag, path: absPath }),
});
const buffer = new edge_parser_1.EdgeBuffer(absPath);

@@ -165,0 +170,0 @@ /**

@@ -11,3 +11,3 @@ /**

import { MacroableConstructorContract } from 'macroable';
import { ParserTagDefinitionContract, Parser, EdgeBuffer } from 'edge-parser';
import { ParserTagDefinitionContract, Parser, EdgeBuffer, ClaimTagFn } from 'edge-parser';
/**

@@ -100,2 +100,9 @@ * The shape in which the loader must resolve the template

/**
* Compiler constructor options
*/
export declare type CompilerOptions = {
cache?: boolean;
claimTag?: ClaimTagFn;
};
/**
* Shape of the template contract

@@ -127,2 +134,6 @@ */

}) => string | void): this;
process(event: 'tag', handler: (data: {
tag: TagToken;
path: string;
}) => void): this;
process(event: 'compiled', handler: (data: {

@@ -162,7 +173,26 @@ compiled: string;

use(pluginFn: (edge: this) => void): this;
/**
* Register a custom tag
*/
registerTag(tag: TagContract): this;
/**
* Register an inline template
*/
registerTemplate(templatePath: string, contents: LoaderTemplate): this;
/**
* Hook into lexical analysis to claim tags
*/
claimTag(fn: ClaimTagFn): this;
/**
* Register a global value
*/
global(key: string, value: any): this;
/**
* Mount/disk
*/
mount(diskName: string): this;
mount(diskName: string, dirPath: string): this;
/**
* Unmount disk
*/
unmount(diskName: string): this;

@@ -169,0 +199,0 @@ getRenderer(): EdgeRendererContract;

@@ -0,1 +1,2 @@

import { ClaimTagFn } from 'edge-parser';
import { Compiler } from '../Compiler';

@@ -10,2 +11,6 @@ import { Processor } from '../Processor';

/**
* Options passed to the compiler instance
*/
private compilerOptions;
/**
* An array of registered plugins

@@ -118,2 +123,6 @@ */

/**
* Register a function to claim tags during the lexal analysis
*/
claimTag(fn: ClaimTagFn): this;
/**
* Returns a new instance of edge. The instance

@@ -120,0 +129,0 @@ * can be used to define locals.

@@ -44,2 +44,8 @@ "use strict";

/**
* Options passed to the compiler instance
*/
this.compilerOptions = {
cache: !!this.options.cache,
};
/**
* An array of registered plugins

@@ -70,3 +76,3 @@ */

*/
this.compiler = new Compiler_1.Compiler(this.loader, this.tags, this.processor, !!this.options.cache);
this.compiler = new Compiler_1.Compiler(this.loader, this.tags, this.processor, this.compilerOptions);
Object.keys(Tags).forEach((name) => this.registerTag(Tags[name]));

@@ -181,2 +187,9 @@ }

/**
* Register a function to claim tags during the lexal analysis
*/
claimTag(fn) {
this.compilerOptions.claimTag = fn;
return this;
}
/**
* Returns a new instance of edge. The instance

@@ -183,0 +196,0 @@ * can be used to define locals.

@@ -0,1 +1,2 @@

import { TagToken } from 'edge-lexer';
import { ProcessorContract, TemplateContract } from '../Contracts';

@@ -9,5 +10,8 @@ /**

/**
* Execute line handler
* Execute tag handler
*/
executeLine(line: string): string;
executeTag(data: {
tag: TagToken;
path: string;
}): void;
/**

@@ -41,3 +45,6 @@ * Execute raw handlers

}) => string | void): this;
process(event: 'line', handler: (line: string) => string | void): this;
process(event: 'tag', handler: (data: {
tag: TagToken;
path: string;
}) => void): this;
process(event: 'compiled', handler: (data: {

@@ -44,0 +51,0 @@ compiled: string;

@@ -21,16 +21,12 @@ "use strict";

/**
* Execute line handler
* Execute tag handler
*/
executeLine(line) {
const handlers = this.handlers.get('line');
executeTag(data) {
const handlers = this.handlers.get('tag');
if (!handlers) {
return line;
return;
}
handlers.forEach((handler) => {
const output = handler(line);
if (output !== undefined) {
line = output;
}
handler(data);
});
return line;
}

@@ -37,0 +33,0 @@ /**

{
"name": "edge.js",
"version": "3.4.0",
"version": "3.5.0",
"description": "Template engine",

@@ -38,5 +38,5 @@ "main": "build/index.js",

"@adonisjs/mrm-preset": "^2.4.0",
"@adonisjs/require-ts": "^1.1.0",
"@adonisjs/require-ts": "^1.1.1",
"@poppinss/dev-utils": "^1.0.11",
"@types/node": "^14.14.7",
"@types/node": "^14.14.10",
"commitizen": "^4.2.2",

@@ -47,3 +47,3 @@ "cz-conventional-changelog": "^3.3.0",

"doctoc": "^1.4.0",
"eslint": "^7.13.0",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",

@@ -56,7 +56,7 @@ "eslint-plugin-adonis": "^1.0.15",

"js-stringify": "^1.0.2",
"mrm": "^2.5.12",
"mrm": "^2.5.13",
"np": "^7.0.0",
"npm-audit-html": "^1.5.0",
"prettier": "^2.1.2",
"typescript": "^4.0.5"
"prettier": "^2.2.1",
"typescript": "^4.1.2"
},

@@ -78,6 +78,6 @@ "config": {

"@poppinss/inspect": "^1.0.1",
"@poppinss/utils": "^2.5.7",
"@poppinss/utils": "^2.5.9",
"edge-error": "^1.0.5",
"edge-lexer": "^3.2.0",
"edge-parser": "^5.4.0",
"edge-lexer": "^3.2.1",
"edge-parser": "^6.0.1",
"he": "^1.2.0",

@@ -84,0 +84,0 @@ "lodash.foreach": "^4.5.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc