edge-parser
Advanced tools
Comparing version 9.0.0-1 to 9.0.0-2
@@ -1,2 +0,2 @@ | ||
export { E as EdgeBuffer, P as Parser, S as Stack } from './index-4a239722.js'; | ||
export { E as EdgeBuffer, P as Parser, S as Stack } from './main-bcdd5c87.js'; | ||
import 'edge-lexer/types'; | ||
@@ -3,0 +3,0 @@ |
@@ -69,6 +69,5 @@ var __defProp = Object.defineProperty; | ||
// src/parser/index.ts | ||
// src/parser/main.ts | ||
import { EOL } from "node:os"; | ||
import { TagTypes, MustacheTypes } from "edge-lexer/types"; | ||
import { Tokenizer } from "edge-lexer"; | ||
import { Tokenizer, MustacheTypes, TagTypes } from "edge-lexer"; | ||
@@ -143,4 +142,4 @@ // src/parser/stringify.ts | ||
// src/parser/make_state_property_accessor.ts | ||
function makeStatePropertyAccessor(propertyName, args) { | ||
// src/parser/expression_builder/member.ts | ||
function makeMemberAccessor(propertyName, args) { | ||
return { | ||
@@ -163,3 +162,3 @@ type: "MemberExpression", | ||
} | ||
return makeStatePropertyAccessor(parser.options.statePropertyName, statement); | ||
return makeMemberAccessor(parser.options.statePropertyName, statement); | ||
} | ||
@@ -434,4 +433,4 @@ }; | ||
// src/parser/make_escape_callable.ts | ||
function makeEscapeCallable(paths, args) { | ||
// src/parser/expression_builder/callable.ts | ||
function makeCallable(paths, args) { | ||
if (typeof paths === "string") { | ||
@@ -482,3 +481,3 @@ return { | ||
// src/parser/index.ts | ||
// src/parser/main.ts | ||
var Parser = class { | ||
@@ -499,7 +498,9 @@ constructor(tags, stack = new Stack(), options) { | ||
utils = { | ||
stringify, | ||
transformAst, | ||
makeCallable, | ||
makeMemberAccessor, | ||
generateAST, | ||
transformAst, | ||
stringify, | ||
makeEscapeCallable, | ||
makeStatePropertyAccessor, | ||
makeEscapeCallable: makeCallable, | ||
makeStatePropertyAccessor: makeMemberAccessor, | ||
collectObjectExpressionProperties, | ||
@@ -518,3 +519,3 @@ collectArrayExpressionProperties, | ||
*/ | ||
getTokenizerOptions(options) { | ||
#getTokenizerOptions(options) { | ||
if (!this.options) { | ||
@@ -533,3 +534,3 @@ return options; | ||
*/ | ||
processEscapedTagToken(token, buffer) { | ||
#processEscapedTagToken(token, buffer) { | ||
const lines = `@${token.properties.name}(${token.properties.jsArg})`.split("\n"); | ||
@@ -543,3 +544,3 @@ lines.forEach((line) => buffer.outputRaw(line)); | ||
*/ | ||
processEscapedMustache(token, buffer) { | ||
#processEscapedMustache(token, buffer) { | ||
const lines = token.type === MustacheTypes.EMUSTACHE ? `{{${token.properties.jsArg}}}`.split("\n") : `{{{${token.properties.jsArg}}}}`.split("\n"); | ||
@@ -551,7 +552,14 @@ lines.forEach((line) => buffer.outputRaw(line)); | ||
*/ | ||
processMustache({ properties, loc, filename, type }, buffer) { | ||
#processMustache({ properties, loc, filename, type }, buffer) { | ||
const node = transformAst(generateAST(properties.jsArg, loc, filename), filename, this); | ||
const expression = type === MustacheTypes.MUSTACHE ? makeEscapeCallable(this.options.escapeCallPath, [node]) : node; | ||
const expression = type === MustacheTypes.MUSTACHE ? makeCallable(this.options.escapeCallPath, [node]) : node; | ||
if (node.type === "TemplateLiteral") { | ||
buffer.outputExpression(stringify(expression), filename, loc.start.line, false); | ||
} else if (node.type === "ObjectExpression") { | ||
buffer.outputExpression( | ||
stringify(makeCallable(this.options.toAttributesCallPath, [node])), | ||
filename, | ||
loc.start.line, | ||
false | ||
); | ||
} else if (node.type === "FunctionDeclaration") { | ||
@@ -567,3 +575,3 @@ buffer.outputExpression(stringify(node), filename, loc.start.line, false); | ||
tokenize(template, options) { | ||
const tokenizer = new Tokenizer(template, this.tags, this.getTokenizerOptions(options)); | ||
const tokenizer = new Tokenizer(template, this.tags, this.#getTokenizerOptions(options)); | ||
tokenizer.parse(); | ||
@@ -590,7 +598,7 @@ return tokenizer.tokens; | ||
case TagTypes.ETAG: | ||
this.processEscapedTagToken(token, buffer); | ||
this.#processEscapedTagToken(token, buffer); | ||
break; | ||
case MustacheTypes.EMUSTACHE: | ||
case MustacheTypes.ESMUSTACHE: | ||
this.processEscapedMustache(token, buffer); | ||
this.#processEscapedMustache(token, buffer); | ||
break; | ||
@@ -602,3 +610,3 @@ case MustacheTypes.SMUSTACHE: | ||
} | ||
this.processMustache(token, buffer); | ||
this.#processMustache(token, buffer); | ||
} | ||
@@ -635,2 +643,5 @@ } | ||
#currentLineNumber = 1; | ||
/** | ||
* Input filename | ||
*/ | ||
#filename; | ||
@@ -637,0 +648,0 @@ /** |
import 'edge-lexer/types'; | ||
export { A as AcornLoc, C as ClaimTagFn, M as MustacheTransformer, O as OnLineFn, b as ParserOptions, a as ParserTagDefinitionContract, T as TagTransformer } from '../index-4a239722.js'; | ||
export { A as AcornLoc, C as ClaimTagFn, M as MustacheTransformer, O as OnLineFn, b as ParserOptions, a as ParserTagDefinitionContract, T as TagTransformer } from '../main-bcdd5c87.js'; |
{ | ||
"name": "edge-parser", | ||
"description": "Parser for edge template engine", | ||
"version": "9.0.0-1", | ||
"version": "9.0.0-2", | ||
"engines": { | ||
@@ -36,2 +36,4 @@ "node": ">=18.16.0" | ||
"@adonisjs/tsconfig": "^1.1.8", | ||
"@commitlint/cli": "^17.6.7", | ||
"@commitlint/config-conventional": "^17.6.7", | ||
"@japa/assert": "2.0.0-1", | ||
@@ -61,3 +63,3 @@ "@japa/runner": "3.0.0-6", | ||
"edge-error": "^4.0.0-0", | ||
"edge-lexer": "^6.0.0-0", | ||
"edge-lexer": "^6.0.0-4", | ||
"js-stringify": "^1.0.2" | ||
@@ -64,0 +66,0 @@ }, |
@@ -1,7 +0,5 @@ | ||
<div align="center"><img src="https://res.cloudinary.com/adonis-js/image/upload/v1620150474/edge-banner_tzmnox.jpg" width="600px"></div> | ||
# Edge Parser | ||
# edge-parser | ||
> Parser to convert edge templates to invokable functions | ||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url] | ||
[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] | ||
@@ -61,13 +59,13 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
const filename = 'eval.edge' | ||
const statePropertyName = 'state' | ||
const escapeCallPath = 'escape' | ||
const outputVar = 'out' | ||
const rethrowCallPath = 'reThrow' | ||
const parser = new Parser({}, new Stack(), { | ||
statePropertyName, | ||
escapeCallPath, | ||
statePropertyName: 'state', | ||
escapeCallPath: 'escape', | ||
toAttributesCallPath: 'toAttributes', | ||
}) | ||
const buffer = new EdgeBuffer(filename, { outputVar, rethrowCallPath }) | ||
const buffer = new EdgeBuffer(filename, { | ||
outputVar: 'out', | ||
rethrowCallPath: 'reThrow' | ||
}) | ||
@@ -77,10 +75,13 @@ parser | ||
.forEach((token) => parser.processToken(token, buffer)) | ||
const output = buffer.flush() | ||
console.log(output) | ||
``` | ||
- All the first set of `const` declarations are the config values that impacts the compiled output. | ||
- `filename` is required to ensure that exceptions stack traces point back to the correct filename. | ||
- `statePropertyName` is the variable name from which the values should be accessed. For example: `{{ username }}` will be compiled as `state.username`. Leave it to empty, if state is not nested inside an object. | ||
- `escapeCallPath` Reference to the `escape` method for escaping interpolation values. For example: `{{ username }}` will be compiled as `escape(state.username)`. The `escape` method should escape only strings and return the other data types as it is. | ||
- `outputVar` is the variable name that holds the output of the compiled template. | ||
- `rethrowCallPath` Reference to the `reThrow` method to raise the template exceptions with the current `$filename` and `$lineNumber`. Check the following compiled output to see how this function is called. | ||
- `filename` is required to ensure that exceptions stack traces point back to the correct filename. | ||
- `statePropertyName` is the variable name from which the values should be accessed. For example: `{{ username }}` will be compiled as `state.username`. Leave it to empty, if state is not nested inside an object. | ||
- `escapeCallPath` Reference to the `escape` method for escaping interpolation values. For example: `{{ username }}` will be compiled as `escape(state.username)`. The `escape` method should escape only strings and return the other data types as it is. | ||
- `toAttributesCallPath`: Reference to the function that will convert an object to HTML attributes. | ||
- `outputVar` is the variable name that holds the output of the compiled template. | ||
- `rethrowCallPath` Reference to the `reThrow` method to raise the template exceptions with the current `$filename` and `$lineNumber`. Check the following compiled output to see how this function is called. | ||
@@ -108,3 +109,3 @@ **Compiled output** | ||
*/ | ||
const fn = new Function('', `return function template (state, escape, reThrow) { ${output} }`)() | ||
const fn = new Function('state, escape, reThrow', output) | ||
@@ -419,4 +420,4 @@ /** | ||
[gh-workflow-image]: https://img.shields.io/github/workflow/status/edge-js/parser/test?style=for-the-badge | ||
[gh-workflow-url]: https://github.com/edge-js/parser/actions/workflows/test.yml "Github action" | ||
[gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/edge-js/parser/checks.yml?style=for-the-badge | ||
[gh-workflow-url]: https://github.com/edge-js/parser/actions/workflows/checks.yml "Github action" | ||
@@ -430,4 +431,1 @@ [npm-image]: https://img.shields.io/npm/v/edge-parser.svg?style=for-the-badge&logo=npm | ||
[license-image]: https://img.shields.io/github/license/edge-js/lexer?style=for-the-badge | ||
[synk-image]: https://img.shields.io/snyk/vulnerabilities/github/edge-js/parser?label=Synk%20Vulnerabilities&style=for-the-badge | ||
[synk-url]: https://snyk.io/test/github/edge-js/parser?targetFile=package.json 'synk' |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1064
0
46011
24
427
Updatededge-lexer@^6.0.0-4