File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
test/unit/modules/compiler Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ const decodeHTMLCached = cached(decodeHTML)
3030let warn
3131let platformGetTagNamespace
3232let platformMustUseProp
33+ let preTransforms
3334let transforms
35+ let postTransforms
3436let delimiters
3537
3638/**
@@ -43,7 +45,9 @@ export function parse (
4345 warn = options . warn || baseWarn
4446 platformGetTagNamespace = options . getTagNamespace || no
4547 platformMustUseProp = options . mustUseProp || no
48+ preTransforms = pluckModuleFunction ( options . modules , 'preTransformNode' )
4649 transforms = pluckModuleFunction ( options . modules , 'transformNode' )
50+ postTransforms = pluckModuleFunction ( options . modules , 'postTransformNode' )
4751 delimiters = options . delimiters
4852 const stack = [ ]
4953 const preserveWhitespace = options . preserveWhitespace !== false
@@ -88,6 +92,11 @@ export function parse (
8892 )
8993 }
9094
95+ // apply pre-transforms
96+ for ( let i = 0 ; i < preTransforms . length ; i ++ ) {
97+ preTransforms [ i ] ( element , options )
98+ }
99+
91100 if ( ! inPre ) {
92101 processPre ( element )
93102 if ( element . pre ) {
@@ -151,6 +160,10 @@ export function parse (
151160 currentParent = element
152161 stack . push ( element )
153162 }
163+ // apply post-transforms
164+ for ( let i = 0 ; i < postTransforms . length ; i ++ ) {
165+ postTransforms [ i ] ( element , options )
166+ }
154167 } ,
155168
156169 end ( ) {
Original file line number Diff line number Diff line change @@ -292,4 +292,22 @@ describe('parser', () => {
292292 const ast = parse ( '<input type="text" name="field1" :value="msg">' , options )
293293 expect ( ast . props ) . toBeUndefined ( )
294294 } )
295+
296+ it ( 'pre/post transforms' , ( ) => {
297+ const options = extend ( { } , baseOptions )
298+ const spy1 = jasmine . createSpy ( 'preTransform' )
299+ const spy2 = jasmine . createSpy ( 'postTransform' )
300+ options . modules = options . modules . concat ( [ {
301+ preTransformNode ( el ) {
302+ spy1 ( el . tag )
303+ } ,
304+ postTransformNode ( el ) {
305+ expect ( el . staticAttrs . length ) . toBe ( 1 )
306+ spy2 ( el . tag )
307+ }
308+ } ] )
309+ parse ( '<img v-pre src="hi">' , options )
310+ expect ( spy1 ) . toHaveBeenCalledWith ( 'img' )
311+ expect ( spy2 ) . toHaveBeenCalledWith ( 'img' )
312+ } )
295313} )
You can’t perform that action at this time.
0 commit comments