Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

htmlc-compiler

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmlc-compiler - npm Package Compare versions

Comparing version 0.1.0 to 0.1.2

17

lib/index.js

@@ -54,3 +54,8 @@ "use strict";

matcher.forEach(function (entry) {
var mask = raw.split((0, util_1.useLoopOpenScope)(loop.name)).pop().split(parser_1.Constants.AST_CLOSE_LOOP_SCOPE).shift().trim();
var mask = raw
.split((0, util_1.useLoopOpenScope)(loop.name))
.pop()
.split("}".concat(parser_1.Constants.HTMLCParserConstants.HTML_COMMENT_CLOSE))
.shift()
.trim();
if (mask.includes(parser_1.Constants.AST_KEYSELF))

@@ -88,4 +93,4 @@ return out.push(mask.replace(parser_1.Constants.AST_KEYSELF, entry));

var nTokens = (0, parser_1.tokenize)(chunk);
nTokens.keys.forEach(function (key) { return chunk = replaceKeyValue(chunk, key, input); });
nTokens.loops.forEach(function (loop) { return chunk = replaceIteratorKey(chunk, loop, input); });
nTokens.keys.forEach(function (key) { return (chunk = replaceKeyValue(chunk, key, input)); });
nTokens.loops.forEach(function (loop) { return (chunk = replaceIteratorKey(chunk, loop, input)); });
return (0, exports.cleanHTML)(chunk, intlCode !== null && intlCode !== void 0 ? intlCode : htmlc_types_1.Locale.en_US);

@@ -101,3 +106,3 @@ }

var p = partials_1[_i];
var signature = (0, util_1.useInlineScope)("".concat(parser_1.Constants.AST_PARTIAL_SIGNATURE, "=").concat(p.name));
var signature = (0, util_1.useInlineScope)("".concat(parser_1.Constants.HTMLCParserConstants.PARTIAL_SIGNATURE, "=").concat(p.name));
if (chunk.includes(signature)) {

@@ -110,3 +115,5 @@ chunk = chunk.replace(signature, (_a = p.renderedChunk) !== null && _a !== void 0 ? _a : p.rawFile);

exports.useRenderContext = useRenderContext;
var useRegistryChunk = function (registry, name) { return registry.filter(function (chunk) { return chunk.name === name; }).shift(); };
var useRegistryChunk = function (registry, name) {
return registry.filter(function (chunk) { return chunk.name === name; }).shift();
};
// call render process with given debug arrangements & latest parser version

@@ -113,0 +120,0 @@ function compile(args) {

@@ -12,11 +12,16 @@ /**

export declare const AST_KEYSELF: string;
export declare const AST_RENDER_SIGNATURE: string;
export declare const AST_PARTIAL_SIGNATURE: string;
export declare const AST_LOOP_SIGNATURE: string;
export declare const AST_PARTIAL_REGGIE: RegExp;
export declare const AST_RENDER_REGGIE: RegExp;
export declare const AST_LOOP_OPEN_REGGIE: RegExp;
export declare const AST_OPEN_SCOPE = "<!--";
export declare const AST_CLOSE_SCOPE = "-->";
export declare const AST_CLOSE_LOOP_SCOPE: string;
export declare const AST_NESTED_KEYPARSE: RegExp;
export declare const HTMLCParserConstants: {
DIRECTIVE_TOKEN: string;
ASSIGN_TOKEN: string;
THIS_TOKEN: string;
KEY_SIGNATURE: string;
KEY_REGGIE: RegExp;
HTML_COMMENT_OPEN: string;
HTML_COMMENT_CLOSE: string;
NESTED_KEY_REGGIE: RegExp;
PARTIAL_SIGNATURE: string;
PARTIAL_REGGIE: RegExp;
LOOP_SIGNATURE: string;
LOOP_OPEN_REGGIE: RegExp;
};
"use strict";
exports.__esModule = true;
exports.AST_NESTED_KEYPARSE = exports.AST_CLOSE_LOOP_SCOPE = exports.AST_CLOSE_SCOPE = exports.AST_OPEN_SCOPE = exports.AST_LOOP_OPEN_REGGIE = exports.AST_RENDER_REGGIE = exports.AST_PARTIAL_REGGIE = exports.AST_LOOP_SIGNATURE = exports.AST_PARTIAL_SIGNATURE = exports.AST_RENDER_SIGNATURE = exports.AST_KEYSELF = exports.AST_TNC = exports.AST_TNO = exports.AST_KNC = exports.AST_KNO = exports.SELF = exports.AST_EQ = exports.AST_DT = void 0;
exports.HTMLCParserConstants = exports.AST_LOOP_OPEN_REGGIE = exports.AST_KEYSELF = exports.AST_TNC = exports.AST_TNO = exports.AST_KNC = exports.AST_KNO = exports.SELF = exports.AST_EQ = exports.AST_DT = void 0;
/**

@@ -15,11 +15,16 @@ * @internal tokens and such for the abstract xing tree modules

exports.AST_KEYSELF = "".concat(exports.AST_TNO).concat(exports.SELF).concat(exports.AST_TNC);
exports.AST_RENDER_SIGNATURE = "".concat(exports.AST_DT, "render");
exports.AST_PARTIAL_SIGNATURE = "".concat(exports.AST_DT, "partial");
exports.AST_LOOP_SIGNATURE = "".concat(exports.AST_DT, "loop");
exports.AST_PARTIAL_REGGIE = /<!--@partial=\w+[\w|\d|/\\]*-->/gi;
exports.AST_RENDER_REGGIE = /<!--@render=\w+.?[\w|\d|.]+-->/gi;
exports.AST_LOOP_OPEN_REGGIE = /<!--@loop\(\w+\){/gi;
exports.AST_OPEN_SCOPE = '<!--';
exports.AST_CLOSE_SCOPE = '-->';
exports.AST_CLOSE_LOOP_SCOPE = exports.AST_TNC + exports.AST_CLOSE_SCOPE;
exports.AST_NESTED_KEYPARSE = /{\w+.?[\w|\d]*}/gi;
exports.HTMLCParserConstants = {
DIRECTIVE_TOKEN: '@',
ASSIGN_TOKEN: '=',
THIS_TOKEN: '_',
KEY_SIGNATURE: '@render',
KEY_REGGIE: /<!--@render=\w+.?[\w|\d|.]+-->/gi,
HTML_COMMENT_OPEN: '<!--',
HTML_COMMENT_CLOSE: '-->',
NESTED_KEY_REGGIE: /{\w+.?[\w|\d]*}/gi,
PARTIAL_SIGNATURE: '@partial',
PARTIAL_REGGIE: /<!--@partial=\w+[\w|\d|/\\]*-->/gi,
LOOP_SIGNATURE: '@loop',
LOOP_OPEN_REGGIE: /<!--@loop\(\w+\){/gi
};
import { Token, AST_MAP, ParsedKey } from 'htmlc-types';
/**
* @constant EMPTY_MAP The initial reducer input for tokenize function
**/
* @constant EMPTY_MAP The initial reducer input for tokenize function
**/
export declare const EMPTY_MAP: AST_MAP;

@@ -6,0 +6,0 @@ /**

@@ -53,4 +53,4 @@ "use strict";

/**
* @constant EMPTY_MAP The initial reducer input for tokenize function
**/
* @constant EMPTY_MAP The initial reducer input for tokenize function
**/
exports.EMPTY_MAP = {

@@ -67,3 +67,5 @@ keys: [],

function hasSymbols(chunk) {
return (chunk.includes(constants_1.AST_RENDER_SIGNATURE) || chunk.includes(constants_1.AST_LOOP_SIGNATURE) || chunk.includes(constants_1.AST_PARTIAL_SIGNATURE));
return (chunk.includes(constants_1.HTMLCParserConstants.KEY_SIGNATURE) ||
chunk.includes(constants_1.HTMLCParserConstants.LOOP_SIGNATURE) ||
chunk.includes(constants_1.HTMLCParserConstants.PARTIAL_SIGNATURE));
}

@@ -78,3 +80,3 @@ exports.hasSymbols = hasSymbols;

var resolvedKeys = parseKeys(mask);
resolvedKeys === null || resolvedKeys === void 0 ? void 0 : resolvedKeys.forEach(function (key) { return mask = mask.replace(key.token, input[key.key]); });
resolvedKeys === null || resolvedKeys === void 0 ? void 0 : resolvedKeys.forEach(function (key) { return (mask = mask.replace(key.token, input[key.key])); });
return mask;

@@ -97,3 +99,3 @@ }

function parseKeys(chunk) {
var matches = chunk.match(constants_1.AST_NESTED_KEYPARSE);
var matches = chunk.match(constants_1.HTMLCParserConstants.NESTED_KEY_REGGIE);
if (!matches)

@@ -110,3 +112,3 @@ return [];

function tokenizeMatch(token) {
if (token.includes(constants_1.AST_LOOP_SIGNATURE)) {
if (token.includes(constants_1.HTMLCParserConstants.LOOP_SIGNATURE)) {
//handle it as a block-level token such as

@@ -125,3 +127,7 @@ /**

// handle it as an inline (non-loop) token such as <!--@partial=foo-->
var name = token.split(constants_1.AST_EQ).pop().split(constants_1.AST_CLOSE_SCOPE).shift();
var name = token
.split(constants_1.AST_EQ)
.pop()
.split(constants_1.HTMLCParserConstants.HTML_COMMENT_CLOSE)
.shift();
return {

@@ -144,7 +150,7 @@ name: name,

switch (curr.signature) {
case constants_1.AST_PARTIAL_SIGNATURE:
case constants_1.HTMLCParserConstants.PARTIAL_SIGNATURE:
return __assign(__assign({}, acc), { partials: __spreadArray(__spreadArray([], acc.partials, true), matches.map(tokenizeMatch), true) });
case constants_1.AST_RENDER_SIGNATURE:
case constants_1.HTMLCParserConstants.KEY_SIGNATURE:
return __assign(__assign({}, acc), { keys: matches.map(tokenizeMatch) });
case constants_1.AST_LOOP_SIGNATURE:
case constants_1.HTMLCParserConstants.LOOP_SIGNATURE:
return __assign(__assign({}, acc), { loops: matches.map(tokenizeMatch) });

@@ -151,0 +157,0 @@ default:

@@ -9,16 +9,22 @@ "use strict";

var constants_1 = require("./constants");
var hasLoop = function (chunk) { return chunk.includes(constants_1.AST_LOOP_SIGNATURE); };
var hasPartial = function (chunk) { return chunk.includes(constants_1.AST_PARTIAL_SIGNATURE); };
var hasKey = function (chunk) { return chunk.includes(constants_1.AST_RENDER_SIGNATURE); };
var hasLoop = function (chunk) {
return chunk.includes(constants_1.HTMLCParserConstants.LOOP_SIGNATURE);
};
var hasPartial = function (chunk) {
return chunk.includes(constants_1.HTMLCParserConstants.PARTIAL_SIGNATURE);
};
var hasKey = function (chunk) {
return chunk.includes(constants_1.HTMLCParserConstants.KEY_SIGNATURE);
};
function matchKeys(chunk) {
var _a;
return (_a = chunk.match(constants_1.AST_RENDER_REGGIE)) !== null && _a !== void 0 ? _a : [];
return (_a = chunk.match(constants_1.HTMLCParserConstants.KEY_REGGIE)) !== null && _a !== void 0 ? _a : [];
}
function matchPartial(chunk) {
var _a;
return (_a = chunk.match(constants_1.AST_PARTIAL_REGGIE)) !== null && _a !== void 0 ? _a : [];
return (_a = chunk.match(constants_1.HTMLCParserConstants.PARTIAL_REGGIE)) !== null && _a !== void 0 ? _a : [];
}
function matchLoops(chunk) {
var out = [];
var _opener = constants_1.AST_LOOP_OPEN_REGGIE;
var _opener = constants_1.HTMLCParserConstants.LOOP_OPEN_REGGIE; //AST_LOOP_OPEN_REGGIE;
var opener = chunk.match(_opener);

@@ -29,3 +35,3 @@ if (opener && (opener === null || opener === void 0 ? void 0 : opener.length) > 0) {

if (chopBottom) {
var ret = chopBottom === null || chopBottom === void 0 ? void 0 : chopBottom.slice(0, chopBottom.indexOf(constants_1.AST_CLOSE_SCOPE) + 4);
var ret = chopBottom === null || chopBottom === void 0 ? void 0 : chopBottom.slice(0, chopBottom.indexOf(constants_1.HTMLCParserConstants.HTML_COMMENT_CLOSE) + 4);
if (ret)

@@ -40,3 +46,3 @@ out.push(ret);

{
signature: constants_1.AST_PARTIAL_SIGNATURE,
signature: constants_1.HTMLCParserConstants.PARTIAL_SIGNATURE,
exists: hasPartial,

@@ -46,3 +52,3 @@ asList: matchPartial

{
signature: constants_1.AST_RENDER_SIGNATURE,
signature: constants_1.HTMLCParserConstants.KEY_SIGNATURE,
exists: hasKey,

@@ -52,3 +58,3 @@ asList: matchKeys

{
signature: constants_1.AST_LOOP_SIGNATURE,
signature: constants_1.HTMLCParserConstants.LOOP_SIGNATURE,
exists: hasLoop,

@@ -55,0 +61,0 @@ asList: matchLoops

@@ -6,8 +6,8 @@ "use strict";

var useInlineScope = function (input) {
return "".concat(constants_1.AST_OPEN_SCOPE).concat(input).concat(constants_1.AST_CLOSE_SCOPE);
return "".concat(constants_1.HTMLCParserConstants.HTML_COMMENT_OPEN).concat(input).concat(constants_1.HTMLCParserConstants.HTML_COMMENT_CLOSE);
};
exports.useInlineScope = useInlineScope;
var useLoopOpenScope = function (name) {
return "".concat(constants_1.AST_OPEN_SCOPE).concat(constants_1.AST_LOOP_SIGNATURE).concat(constants_1.AST_KNO).concat(name).concat(constants_1.AST_KNC).concat(constants_1.AST_TNO);
return "".concat(constants_1.HTMLCParserConstants.HTML_COMMENT_OPEN).concat(constants_1.HTMLCParserConstants.LOOP_SIGNATURE).concat(constants_1.AST_KNO).concat(name).concat(constants_1.AST_KNC).concat(constants_1.AST_TNO);
};
exports.useLoopOpenScope = useLoopOpenScope;
{
"name": "htmlc-compiler",
"version": "0.1.0",
"version": "0.1.2",
"scripts": {
"build": "tsc",
"dev": "tsc -w"
"build": "yarn lint && tsc",
"dev": "tsc -w",
"lint": "prettier --write ./src"
},

@@ -9,0 +10,0 @@ "dependencies": {

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