edge-parser
Advanced tools
Comparing version 6.0.0 to 6.0.1
export { Stack } from './src/Stack'; | ||
export { Parser } from './src/Parser'; | ||
export { EdgeBuffer } from './src/EdgeBuffer'; | ||
export { ParserTagDefinitionContract, AcornLoc } from './src/Contracts'; | ||
export * from './src/Contracts'; | ||
/** | ||
@@ -6,0 +6,0 @@ * Names of supported expressions |
@@ -22,2 +22,5 @@ "use strict"; | ||
}); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -38,2 +41,3 @@ if (mod && mod.__esModule) return mod; | ||
Object.defineProperty(exports, "EdgeBuffer", { enumerable: true, get: function () { return EdgeBuffer_1.EdgeBuffer; } }); | ||
__exportStar(require("./src/Contracts"), exports); | ||
const ExpressionsList = __importStar(require("./src/Expressions")); | ||
@@ -40,0 +44,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { TagToken, LexerTagDefinitionContract } from 'edge-lexer'; | ||
import { TagToken, LexerTagDefinitionContract, MustacheToken } from 'edge-lexer'; | ||
import { Parser } from '../Parser'; | ||
@@ -24,1 +24,12 @@ import { EdgeBuffer } from '../EdgeBuffer'; | ||
export declare type TagTransformer = (tag: TagToken) => void; | ||
export declare type MustacheTransformer = (tag: MustacheToken) => void; | ||
export declare type ClaimTagFn = (name: string) => LexerTagDefinitionContract | null; | ||
/** | ||
* Parser options | ||
*/ | ||
export declare type ParserOptions = { | ||
async?: boolean; | ||
onTag?: TagTransformer; | ||
onMustache?: MustacheTransformer; | ||
claimTag?: ClaimTagFn; | ||
}; |
@@ -16,3 +16,3 @@ "use strict"; | ||
toStatement(statement, filename, parser) { | ||
if (!parser.asyncMode) { | ||
if (!parser.options.async) { | ||
const { line, col } = parser.utils.getExpressionLoc(statement); | ||
@@ -19,0 +19,0 @@ throw new edge_error_1.EdgeError(UNALLOWED_EXPRESSION_MESSAGE, 'E_PARSER_ERROR', { |
@@ -1,2 +0,2 @@ | ||
import { Token, LexerTagDefinitionContract } from 'edge-lexer'; | ||
import { Token } from 'edge-lexer'; | ||
import { Stack } from '../Stack'; | ||
@@ -9,3 +9,3 @@ import { stringify } from './stringify'; | ||
import { makeStatePropertyAccessor } from './makeStatePropertyAccessor'; | ||
import { ParserTagDefinitionContract, TagTransformer } from '../Contracts'; | ||
import { ParserTagDefinitionContract, ParserOptions } from '../Contracts'; | ||
import { collectObjectExpressionProperties } from './collectObjectExpressionProperties'; | ||
@@ -38,7 +38,7 @@ /** | ||
}; | ||
asyncMode: boolean; | ||
stack: Stack; | ||
options: ParserOptions; | ||
constructor(tags: { | ||
[key: string]: ParserTagDefinitionContract; | ||
}, asyncMode?: boolean, stack?: Stack); | ||
}, stack?: Stack, options?: ParserOptions); | ||
/** | ||
@@ -78,4 +78,2 @@ * Parser utilities work with the AST | ||
filename: string; | ||
onLine?: (line: string) => string; | ||
claimTag?: (name: string) => LexerTagDefinitionContract | null; | ||
}): Token[]; | ||
@@ -85,3 +83,3 @@ /** | ||
*/ | ||
processToken(token: Token, buffer: EdgeBuffer, onTag?: TagTransformer): void; | ||
processToken(token: Token, buffer: EdgeBuffer): void; | ||
} |
@@ -44,6 +44,6 @@ "use strict"; | ||
class Parser { | ||
constructor(tags, asyncMode = false, stack = new Stack_1.Stack()) { | ||
constructor(tags, stack = new Stack_1.Stack(), options = {}) { | ||
this.tags = tags; | ||
this.asyncMode = asyncMode; | ||
this.stack = stack; | ||
this.options = options; | ||
/** | ||
@@ -126,3 +126,8 @@ * Parser utilities work with the AST | ||
tokenize(template, options) { | ||
const tokenizer = new edge_lexer_1.Tokenizer(template, this.tags, options); | ||
const tokenizer = new edge_lexer_1.Tokenizer(template, this.tags, this.options.claimTag | ||
? { | ||
claimTag: this.options.claimTag, | ||
filename: options.filename, | ||
} | ||
: options); | ||
tokenizer.parse(); | ||
@@ -134,3 +139,3 @@ return tokenizer.tokens; | ||
*/ | ||
processToken(token, buffer, onTag) { | ||
processToken(token, buffer) { | ||
switch (token.type) { | ||
@@ -144,4 +149,4 @@ case 'raw': | ||
case edge_lexer_1.TagTypes.TAG: | ||
if (typeof onTag === 'function') { | ||
onTag(token); | ||
if (typeof this.options.onTag === 'function') { | ||
this.options.onTag(token); | ||
} | ||
@@ -159,2 +164,5 @@ this.tags[token.properties.name].compile(this, buffer, token); | ||
case edge_lexer_1.MustacheTypes.MUSTACHE: | ||
if (typeof this.options.onMustache === 'function') { | ||
this.options.onMustache(token); | ||
} | ||
this.processMustache(token, buffer); | ||
@@ -161,0 +169,0 @@ } |
{ | ||
"name": "edge-parser", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "Parser for edge template engine", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
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
72210
1603