diff --git a/index.ts b/index.ts index af77445..5327552 100644 --- a/index.ts +++ b/index.ts @@ -9,7 +9,14 @@ export { Parser } from './src/Parser' export { EdgeBuffer } from './src/EdgeBuffer' -export { ParseTagDefininationContract } from './src/Contracts' +export { + ParserToken, + ParserTagToken, + ParserRawToken, + ParserMustacheToken, + ParserNewLineToken, + ParseTagDefininationContract, +} from './src/Contracts' import * as ExpressionsList from './src/Expressions' /** diff --git a/src/Contracts/index.ts b/src/Contracts/index.ts index 0ad1b80..91cd710 100644 --- a/src/Contracts/index.ts +++ b/src/Contracts/index.ts @@ -44,28 +44,27 @@ export type AcornLoc = { } /** - * Extended tokens allows a custom filename for each token. This is helpful + * ------------------------------------------------------------------------ + * Parser tokens allows a custom filename for each token. This is helpful * when tokens of multiple files are merged together before they are * passed to parser. + * ------------------------------------------------------------------------ */ -export type ExtendedNewLineToken = NewLineToken & { +export type ParserNewLineToken = NewLineToken & { filename?: string, } -export type ExtendRawToken = RawToken & { +export type ParserRawToken = RawToken & { filename?: string, } -export type ExtendedTagToken = TagToken & { +export type ParserTagToken = TagToken & { filename?: string, - children: ExtendedToken[]; + children: ParserToken[]; } -export type ExtendedMustacheToken = MustacheToken & { +export type ParserMustacheToken = MustacheToken & { filename?: string, } -export type ExtendedToken = ExtendedNewLineToken | - ExtendRawToken | - ExtendedTagToken | - ExtendedMustacheToken +export type ParserToken = ParserNewLineToken | ParserRawToken | ParserTagToken | ParserMustacheToken diff --git a/src/Parser/index.ts b/src/Parser/index.ts index 5a843fb..41ea24a 100644 --- a/src/Parser/index.ts +++ b/src/Parser/index.ts @@ -21,7 +21,7 @@ import { Tokenizer, TagToken, MustacheTypes, TagTypes } from 'edge-lexer' import { EdgeBuffer } from '../EdgeBuffer' import { getCallExpression } from '../utils' import * as Expressions from '../Expressions' -import { ParseTagDefininationContract, AcornLoc, ExtendedToken } from '../Contracts' +import { ParseTagDefininationContract, AcornLoc, ParserToken } from '../Contracts' /** * Edge parser converts template strings to an invokable function. This module @@ -105,7 +105,7 @@ export class Parser { * Process a given [edge-lexer](https://github.com/edge-js/lexer) token and * write it's output to the edge buffer. */ - public processLexerToken (token: ExtendedToken, buffer: EdgeBuffer): void { + public processLexerToken (token: ParserToken, buffer: EdgeBuffer): void { /** * Raw node */ @@ -205,7 +205,7 @@ export class Parser { * parse.generateLexerTokens('Hello {{ username }}') * ``` */ - public generateLexerTokens (template: string): ExtendedToken[] { + public generateLexerTokens (template: string): ParserToken[] { const tokenizer = new Tokenizer(template, this.tags, this.options) tokenizer.parse() diff --git a/test/parser.spec.ts b/test/parser.spec.ts index cf8df4e..cef2a28 100644 --- a/test/parser.spec.ts +++ b/test/parser.spec.ts @@ -16,7 +16,7 @@ import dedent from 'dedent-js' import { Parser } from '../src/Parser' import { EdgeBuffer } from '../src/EdgeBuffer' -import { ExtendedTagToken } from '../src/Contracts' +import { ParserTagToken } from '../src/Contracts' import { MustacheToken, TagToken } from 'edge-lexer/build/src/Contracts' function normalizeNewLines (value) { @@ -297,7 +297,7 @@ test.group('Parser', () => { `) tokens[0].filename = 'bar.edge'; - (tokens[0] as ExtendedTagToken).children[1].filename = 'baz.edge' + (tokens[0] as ParserTagToken).children[1].filename = 'baz.edge' parser.processLexerToken(tokens[0], new EdgeBuffer()) } catch ({ stack, line, col }) {