@@ -65,11 +65,12 @@ export function assembleFromSource(
65
65
template = template || { source : '' }
66
66
67
67
const hasScopedStyle = styles . some ( style => style . scoped === true )
68
- const hasStyle = styles . length > 0
68
+ const hasStyle = styles . some ( style => Boolean ( style . source ) )
69
69
const e = ( any : any ) : string => JSON . stringify ( any )
70
- const createImport = ( name : string , value : string ) => value . startsWith ( '~' )
71
- ? `import ${ name } from '${ value . substr ( 1 ) } '`
72
- : `const ${ name } = ${ value } `
70
+ const createImport = ( name : string , value : string ) =>
71
+ value . startsWith ( '~' )
72
+ ? `import ${ name } from '${ value . substr ( 1 ) } '`
73
+ : `const ${ name } = ${ value } `
73
74
const o = e
74
75
const IDENTIFIER = / ^ [ a - z 0 - 9 ] + $ / i
75
76
@@ -293,21 +294,35 @@ const __vue_template__ = typeof __vue_render__ !== 'undefined'
293
294
/* style */
294
295
const __vue_inject_styles__ = ${ hasStyle } ? function (inject) {
295
296
if (!inject) return
296
- ${ styles . map (
297
- ( style , index ) => {
298
- const source = IDENTIFIER . test ( style . source ) ? style . source : e ( style . source )
299
- const map = ! compiler . template . isProduction
300
- ? ( typeof style . map === 'string' && IDENTIFIER . test ( style . map ) ? style . map : o ( style . map ) )
301
- : undefined
302
- const tokens = typeof style . module === 'string' && IDENTIFIER . test ( style . module ) ? style . module : o ( style . module )
303
-
304
- return `inject("${ scopeId + '_' + index } ", { source: ${ source } , map: ${ map } , media: ${ e ( style . media ) } })` +
305
- '\n' +
297
+ ${ styles . map ( ( style , index ) => {
298
+ const source = IDENTIFIER . test ( style . source )
299
+ ? style . source
300
+ : e ( style . source )
301
+ const map = ! compiler . template . isProduction
302
+ ? typeof style . map === 'string' && IDENTIFIER . test ( style . map )
303
+ ? style . map
304
+ : o ( style . map )
305
+ : undefined
306
+ const tokens =
307
+ typeof style . module === 'string' && IDENTIFIER . test ( style . module )
308
+ ? style . module
309
+ : o ( style . module )
310
+
311
+ return (
312
+ ( source
313
+ ? `inject("${ scopeId +
314
+ '_' +
315
+ index } ", { source: ${ source } , map: ${ map } , media: ${ e (
316
+ style . media
317
+ ) } })\n`
318
+ : '' ) +
306
319
( style . moduleName
307
- ? `Object.defineProperty(this, "${ style . moduleName } ", { value: ${ tokens } })` + '\n'
320
+ ? `Object.defineProperty(this, "${
321
+ style . moduleName
322
+ } ", { value: ${ tokens } })` + '\n'
308
323
: '' )
309
- }
310
- ) }
324
+ )
325
+ } ) }
311
326
} : undefined
312
327
/* scoped */
313
328
const __vue_scope_id__ = ${ e ( hasScopedStyle ) } ? "${ scopeId } " : undefined
0 commit comments