Skip to content

Commit

Permalink
refactor: rename ExtendedTokens to ParserTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 14, 2019
1 parent ce38709 commit 3283734
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
9 changes: 8 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down
19 changes: 9 additions & 10 deletions src/Contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/Parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions test/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 }) {
Expand Down

0 comments on commit 3283734

Please sign in to comment.