edge-parser
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -1,8 +0,10 @@ | ||
import { ITagDefination, IBlockNode } from 'edge-lexer/build/src/Contracts'; | ||
import { ITagToken } from 'edge-lexer/build/src/Contracts'; | ||
import { Parser } from '../Parser'; | ||
import { EdgeBuffer } from '../EdgeBuffer'; | ||
export interface ITag extends ITagDefination { | ||
compile(parser: Parser, buffer: EdgeBuffer, token: IBlockNode): void; | ||
} | ||
export declare type ILoc = { | ||
export declare type ITag = { | ||
compile(parser: Parser, buffer: EdgeBuffer, token: ITagToken): void; | ||
seekable: boolean; | ||
block: boolean; | ||
}; | ||
export declare type IAcornLoc = { | ||
start: { | ||
@@ -9,0 +11,0 @@ line: number; |
@@ -1,4 +0,4 @@ | ||
import * as Contracts from 'edge-lexer/build/src/Contracts'; | ||
import { ILoc, IToken } from 'edge-lexer/build/src/Contracts'; | ||
import { EdgeBuffer } from '../EdgeBuffer'; | ||
import { ITag, ILoc } from '../Contracts'; | ||
import { ITag, IAcornLoc } from '../Contracts'; | ||
declare type parserOptions = { | ||
@@ -17,11 +17,11 @@ filename: string; | ||
acornToEdgeExpression(statement: any): any; | ||
patchLoc(loc: ILoc, tokenLine: number): void; | ||
patchLoc(loc: IAcornLoc, lexerLoc: ILoc): void; | ||
statementToString(statement: any): string; | ||
processTokens(tokens: any, wrapAsFunction?: boolean): string; | ||
processToken(token: any, buffer: EdgeBuffer): void; | ||
generateAst(arg: string, lineno: number): any; | ||
generateTokens(template: string): Contracts.INode[]; | ||
parseJsString(arg: string, lineno: number): any; | ||
generateAst(arg: string, lexerLoc: ILoc): any; | ||
generateTokens(template: string): IToken[]; | ||
parseJsString(jsArg: string, loc: ILoc): any; | ||
parseTemplate(template: string): string; | ||
} | ||
export {}; |
@@ -7,4 +7,4 @@ "use strict"; | ||
const edge_lexer_1 = require("edge-lexer"); | ||
const Contracts = require("edge-lexer/build/src/Contracts"); | ||
const edge_error_1 = require("edge-error"); | ||
const Contracts_1 = require("edge-lexer/build/src/Contracts"); | ||
const EdgeBuffer_1 = require("../EdgeBuffer"); | ||
@@ -33,5 +33,8 @@ const utils_1 = require("../utils"); | ||
} | ||
patchLoc(loc, tokenLine) { | ||
loc.start.line = (loc.start.line + tokenLine) - 1; | ||
loc.end.line = (loc.end.line + tokenLine) - 1; | ||
patchLoc(loc, lexerLoc) { | ||
loc.start.line = (loc.start.line + lexerLoc.start.line) - 1; | ||
loc.end.line = (loc.end.line + lexerLoc.start.line) - 1; | ||
if (loc.start.line === 1) { | ||
loc.start.column = loc.start.column + lexerLoc.start.col; | ||
} | ||
} | ||
@@ -55,33 +58,34 @@ statementToString(statement) { | ||
} | ||
if (token.type === 'block') { | ||
if (token.type === Contracts_1.TagTypes.TAG) { | ||
this.tags[token.properties.name].compile(this, buffer, token); | ||
return; | ||
} | ||
if (token.type === Contracts_1.TagTypes.ETAG) { | ||
buffer.writeLine(`@{token.properties.name}(${token.properties.jsArg})`); | ||
return; | ||
} | ||
const mustacheToken = token; | ||
if (mustacheToken.properties.name === Contracts.MustacheType.EMUSTACHE) { | ||
if (mustacheToken.type === Contracts_1.MustacheTypes.EMUSTACHE) { | ||
buffer.writeLine(`\`{{${mustacheToken.properties.jsArg}}}\``); | ||
return; | ||
} | ||
if (mustacheToken.properties.name === Contracts.MustacheType.ESMUSTACHE) { | ||
if (mustacheToken.type === Contracts_1.MustacheTypes.ESMUSTACHE) { | ||
buffer.writeLine(`\`{{{${mustacheToken.properties.jsArg}}}}\``); | ||
return; | ||
} | ||
if (mustacheToken.type === 'mustache') { | ||
const node = this.parseJsString(mustacheToken.properties.jsArg, mustacheToken.lineno); | ||
if (mustacheToken.properties.name === Contracts.MustacheType.MUSTACHE) { | ||
buffer.writeInterpol(this.statementToString(utils_1.getCallExpression([node], 'escape'))); | ||
return; | ||
} | ||
if ([Contracts_1.MustacheTypes.SMUSTACHE, Contracts_1.MustacheTypes.MUSTACHE].indexOf(mustacheToken.type) > -1) { | ||
const node = this.parseJsString(mustacheToken.properties.jsArg, mustacheToken.loc); | ||
const expression = mustacheToken.type === Contracts_1.MustacheTypes.MUSTACHE ? utils_1.getCallExpression([node], 'escape') : node; | ||
if (node.type === 'TemplateLiteral') { | ||
buffer.writeLine(this.statementToString(node)); | ||
buffer.writeLine(this.statementToString(expression)); | ||
return; | ||
} | ||
buffer.writeInterpol(this.statementToString(node)); | ||
buffer.writeInterpol(this.statementToString(expression)); | ||
} | ||
} | ||
generateAst(arg, lineno) { | ||
generateAst(arg, lexerLoc) { | ||
try { | ||
const ast = acorn.parse(arg, Object.assign(this.acornArgs, { | ||
onToken: (token) => { | ||
this.patchLoc(token.loc, lineno); | ||
this.patchLoc(token.loc, lexerLoc); | ||
}, | ||
@@ -92,5 +96,7 @@ })); | ||
catch (error) { | ||
const line = (error.loc.line + lexerLoc.start.line) - 1; | ||
const col = error.loc.line === 1 ? error.loc.column + lexerLoc.start.col : error.loc.column; | ||
throw new edge_error_1.EdgeError(error.message.replace(/\(\d+:\d+\)/, ''), 'E_ACORN_ERROR', { | ||
line: (error.loc.line + lineno) - 1, | ||
col: error.loc.column, | ||
line, | ||
col, | ||
filename: this.options.filename, | ||
@@ -105,4 +111,4 @@ }); | ||
} | ||
parseJsString(arg, lineno) { | ||
const ast = this.generateAst(arg, lineno); | ||
parseJsString(jsArg, loc) { | ||
const ast = this.generateAst(jsArg, loc); | ||
return this.acornToEdgeExpression(ast.body[0]); | ||
@@ -109,0 +115,0 @@ } |
@@ -0,1 +1,11 @@ | ||
<a name="2.0.1"></a> | ||
## [2.0.1](https://github.com/edge-js/parser/compare/v2.0.0...v2.0.1) (2018-11-09) | ||
### Bug Fixes | ||
* **parser:** report correct column number ([98b06b5](https://github.com/edge-js/parser/commit/98b06b5)) | ||
<a name="2.0.0"></a> | ||
@@ -2,0 +12,0 @@ # [2.0.0](https://github.com/edge-js/parser/compare/v1.0.16...v2.0.0) (2018-11-05) |
{ | ||
"name": "edge-parser", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Parser for edge template engine", | ||
@@ -37,7 +37,7 @@ "scripts": { | ||
"edge-error": "^1.0.1", | ||
"edge-lexer": "^1.0.8" | ||
"edge-lexer": "^2.0.1" | ||
}, | ||
"devDependencies": { | ||
"@adonisjs/mrm-preset": "^1.0.14", | ||
"@types/node": "^10.12.2", | ||
"@types/node": "^10.12.3", | ||
"commitizen": "^3.0.4", | ||
@@ -44,0 +44,0 @@ "coveralls": "^3.0.2", |
@@ -15,3 +15,3 @@ # Edge Parser | ||
``` | ||
```edge | ||
Hello {{ username }} | ||
@@ -22,3 +22,3 @@ ``` | ||
``` | ||
```js | ||
(function (template, ctx) { | ||
@@ -28,3 +28,2 @@ let out = '' | ||
out += `${ctx.escape(ctx.resolve('username'))}` | ||
out += '\n' | ||
return out | ||
@@ -31,0 +30,0 @@ })(ctx) |
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
29593
520
184
+ Addededge-lexer@2.2.0(transitive)
- Removededge-lexer@1.0.8(transitive)
- Removedis-whitespace-character@1.0.4(transitive)
Updatededge-lexer@^2.0.1