diff --git a/README.md b/README.md index 471abd8..6ef98b4 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,7 @@ interface TemplateCompileOptions { } interface TemplateCompileResult { + ast: Object | undefined code: string source: string tips: string[] diff --git a/lib/compileTemplate.ts b/lib/compileTemplate.ts index 638f77b..ad1cf0a 100644 --- a/lib/compileTemplate.ts +++ b/lib/compileTemplate.ts @@ -28,6 +28,7 @@ export interface TemplateCompileOptions { } export interface TemplateCompileResult { + ast: Object | undefined code: string source: string tips: (string | ErrorWithRange)[] @@ -47,6 +48,7 @@ export function compileTemplate( ) } else if (preprocessLang) { return { + ast: {}, code: `var render = function () {}\n` + `var staticRenderFns = []\n`, source: options.source, tips: [ @@ -124,13 +126,14 @@ function actuallyCompile( }) } - const { render, staticRenderFns, tips, errors } = compile( + const { ast, render, staticRenderFns, tips, errors } = compile( source, finalCompilerOptions ) if (errors && errors.length) { return { + ast, code: `var render = function () {}\n` + `var staticRenderFns = []\n`, source, tips, @@ -181,6 +184,7 @@ function actuallyCompile( } return { + ast, code, source, tips, diff --git a/lib/types.ts b/lib/types.ts index f2542bb..c534544 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -33,6 +33,8 @@ export interface VueTemplateCompiler { export interface VueTemplateCompilerOptions { modules?: Object[] outputSourceRange?: boolean + whitespace?: 'preserve' | 'condense' + directives?: { [key: string]: Function } } export interface VueTemplateCompilerParseOptions { @@ -46,7 +48,7 @@ export interface ErrorWithRange { } export interface VueTemplateCompilerResults { - ast: Object | void + ast: Object | undefined render: string staticRenderFns: string[] errors: (string | ErrorWithRange)[] diff --git a/test/compileTemplate.spec.ts b/test/compileTemplate.spec.ts index de29064..762a3ff 100644 --- a/test/compileTemplate.spec.ts +++ b/test/compileTemplate.spec.ts @@ -34,6 +34,7 @@ test('should work', () => { expect(result.code).toMatch(`render._withStripped = true`) // should prefix bindings expect(result.code).toMatch(`_vm.render`) + expect(result.ast).not.toBeUndefined() }) test('preprocess pug', () => {
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: