1
- import {
2
- VueTemplateCompiler ,
3
- VueTemplateCompilerOptions
4
- } from './types'
1
+ import { VueTemplateCompiler , VueTemplateCompilerOptions } from './types'
5
2
6
- import assetUrlsModule , { AssetURLOptions } from './templateCompilerModules/assetUrl'
3
+ import assetUrlsModule , {
4
+ AssetURLOptions
5
+ } from './templateCompilerModules/assetUrl'
7
6
import srcsetModule from './templateCompilerModules/srcset'
8
7
9
8
const prettier = require ( 'prettier' )
@@ -31,43 +30,49 @@ export interface TemplateCompileResult {
31
30
errors : string [ ]
32
31
}
33
32
34
- export function compileTemplate (
33
+ export function compileTemplate (
35
34
options : TemplateCompileOptions
36
35
) : TemplateCompileResult {
37
36
const { preprocessLang } = options
38
37
const preprocessor = preprocessLang && consolidate [ preprocessLang ]
39
38
if ( preprocessor ) {
40
- return actuallyCompile ( Object . assign ( { } , options , {
41
- source : preprocess ( options , preprocessor )
42
- } ) )
39
+ return actuallyCompile (
40
+ Object . assign ( { } , options , {
41
+ source : preprocess ( options , preprocessor )
42
+ } )
43
+ )
43
44
} else if ( preprocessLang ) {
44
45
return {
45
- code : (
46
- `var render = function () {}\n` +
47
- `var staticRenderFns = []\n`
48
- ) ,
46
+ code : `var render = function () {}\n` + `var staticRenderFns = []\n` ,
49
47
source : options . source ,
50
- tips : [ `Component ${ options . filename } uses lang ${ preprocessLang } for template. Please install the language preprocessor.` ] ,
51
- errors : [ `Component ${ options . filename } uses lang ${ preprocessLang } for template, however it is not installed.` ]
52
- } ;
48
+ tips : [
49
+ `Component ${
50
+ options . filename
51
+ } uses lang ${ preprocessLang } for template. Please install the language preprocessor.`
52
+ ] ,
53
+ errors : [
54
+ `Component ${
55
+ options . filename
56
+ } uses lang ${ preprocessLang } for template, however it is not installed.`
57
+ ]
58
+ }
53
59
} else {
54
60
return actuallyCompile ( options )
55
61
}
56
62
}
57
63
58
- function preprocess (
64
+ function preprocess (
59
65
options : TemplateCompileOptions ,
60
66
preprocessor : any
61
67
) : string {
62
- const {
63
- source,
64
- filename,
65
- preprocessOptions
66
- } = options
68
+ const { source, filename, preprocessOptions } = options
67
69
68
- const finalPreprocessOptions = Object . assign ( {
69
- filename
70
- } , preprocessOptions )
70
+ const finalPreprocessOptions = Object . assign (
71
+ {
72
+ filename
73
+ } ,
74
+ preprocessOptions
75
+ )
71
76
72
77
// Consolidate exposes a callback based API, but the callback is in fact
73
78
// called synchronously for most templating engines. In our case, we have to
@@ -87,7 +92,7 @@ function preprocess (
87
92
return res
88
93
}
89
94
90
- function actuallyCompile (
95
+ function actuallyCompile (
91
96
options : TemplateCompileOptions
92
97
) : TemplateCompileResult {
93
98
const {
@@ -101,9 +106,8 @@ function actuallyCompile (
101
106
optimizeSSR = false
102
107
} = options
103
108
104
- const compile = optimizeSSR && compiler . ssrCompile
105
- ? compiler . ssrCompile
106
- : compiler . compile
109
+ const compile =
110
+ optimizeSSR && compiler . ssrCompile ? compiler . ssrCompile : compiler . compile
107
111
108
112
let finalCompilerOptions = compilerOptions
109
113
if ( transformAssetUrls ) {
@@ -114,23 +118,18 @@ function actuallyCompile (
114
118
srcsetModule ( )
115
119
]
116
120
finalCompilerOptions = Object . assign ( { } , compilerOptions , {
117
- modules : [ ...builtInModules , ...compilerOptions . modules || [ ] ]
121
+ modules : [ ...builtInModules , ...( compilerOptions . modules || [ ] ) ]
118
122
} )
119
123
}
120
124
121
- const {
122
- render,
123
- staticRenderFns,
124
- tips,
125
- errors
126
- } = compile ( source , finalCompilerOptions )
125
+ const { render, staticRenderFns, tips, errors } = compile (
126
+ source ,
127
+ finalCompilerOptions
128
+ )
127
129
128
130
if ( errors && errors . length ) {
129
131
return {
130
- code : (
131
- `var render = function () {}\n` +
132
- `var staticRenderFns = []\n`
133
- ) ,
132
+ code : `var render = function () {}\n` + `var staticRenderFns = []\n` ,
134
133
source,
135
134
tips,
136
135
errors
@@ -148,11 +147,12 @@ function actuallyCompile (
148
147
149
148
// transpile code with vue-template-es2015-compiler, which is a forked
150
149
// version of Buble that applies ES2015 transforms + stripping `with` usage
151
- let code = transpile (
152
- `var __render__ = ${ toFunction ( render ) } \n` +
153
- `var __staticRenderFns__ = [${ staticRenderFns . map ( toFunction ) } ]` ,
154
- finalTranspileOptions
155
- ) + `\n`
150
+ let code =
151
+ transpile (
152
+ `var __render__ = ${ toFunction ( render ) } \n` +
153
+ `var __staticRenderFns__ = [${ staticRenderFns . map ( toFunction ) } ]` ,
154
+ finalTranspileOptions
155
+ ) + `\n`
156
156
157
157
// #23 we use __render__ to avoid `render` not being prefixed by the
158
158
// transpiler when stripping with, but revert it back to `render` to
0 commit comments