diff --git a/src/index.ts b/src/index.ts index eb84c7c6..071045f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -660,6 +660,10 @@ export const plugin: Plugin = { result = printIndent(previousToken, result, indent, indentLevel); result += '-'; break; + case 'yield': + result = printIndent(previousToken, result, indent, indentLevel); + result += 'yield'; + break; default: throw new Error('Unhandled token: ' + JSON.stringify(token)); } diff --git a/src/pug-lexer.d.ts b/src/pug-lexer.d.ts index 52b026f3..4e20a316 100644 --- a/src/pug-lexer.d.ts +++ b/src/pug-lexer.d.ts @@ -46,7 +46,8 @@ declare module 'pug-lexer' { | 'text-html' | 'text' | 'when' - | 'while'; + | 'while' + | 'yield'; export interface LexToken { type: Type; @@ -197,6 +198,8 @@ declare module 'pug-lexer' { export type BlockcodeToken = LexToken<'blockcode'>; + export type YieldToken = LexToken<'yield'>; + export type Token = | AndAttributesToken | AttributeToken @@ -238,7 +241,8 @@ declare module 'pug-lexer' { | TextHtmlToken | TextToken | WhenToken - | WhileToken; + | WhileToken + | YieldToken; export type LexerFunction = (type: string, exp?: any) => boolean; export interface LexerOptions { diff --git a/test/yield/formatted.pug b/test/yield/formatted.pug new file mode 100644 index 00000000..95f66885 --- /dev/null +++ b/test/yield/formatted.pug @@ -0,0 +1,4 @@ +head + script(src="/jquery.js") + yield + script(src="/jquery.ui.js") diff --git a/test/yield/unformatted.pug b/test/yield/unformatted.pug new file mode 100644 index 00000000..95f66885 --- /dev/null +++ b/test/yield/unformatted.pug @@ -0,0 +1,4 @@ +head + script(src="/jquery.js") + yield + script(src="/jquery.ui.js") diff --git a/test/yield/yield.test.ts b/test/yield/yield.test.ts new file mode 100644 index 00000000..8202c3b4 --- /dev/null +++ b/test/yield/yield.test.ts @@ -0,0 +1,14 @@ +import { readFileSync } from 'fs'; +import { resolve } from 'path'; +import { format } from 'prettier'; +import { plugin } from './../../src/index'; + +describe('Yield', () => { + test('should handle yield token', () => { + const expected: string = readFileSync(resolve(__dirname, 'formatted.pug'), 'utf8'); + const code: string = readFileSync(resolve(__dirname, 'unformatted.pug'), 'utf8'); + const actual: string = format(code, { parser: 'pug' as any, plugins: [plugin] }); + + expect(actual).toBe(expected); + }); +});