Skip to content

Commit 3edfc45

Browse files
committed
support postTransform as well
1 parent 3ddef0c commit 3edfc45

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/compiler/parser/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let platformGetTagNamespace
3333
let platformMustUseProp
3434
let preTransforms
3535
let transforms
36+
let postTransforms
3637
let delimiters
3738

3839
/**
@@ -47,6 +48,7 @@ export function parse (
4748
platformMustUseProp = options.mustUseProp || no
4849
preTransforms = pluckModuleFunction(options.modules, 'preTransformNode')
4950
transforms = pluckModuleFunction(options.modules, 'transformNode')
51+
postTransforms = pluckModuleFunction(options.modules, 'postTransformNode')
5052
delimiters = options.delimiters
5153
const stack = []
5254
let root
@@ -165,6 +167,10 @@ export function parse (
165167
currentParent = element
166168
stack.push(element)
167169
}
170+
// apply post-transforms
171+
for (let i = 0; i < postTransforms.length; i++) {
172+
postTransforms[i](element, options)
173+
}
168174
},
169175

170176
end () {

test/unit/modules/compiler/parser.spec.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,21 @@ describe('parser', () => {
316316
expect(ast.props).toBeUndefined()
317317
})
318318

319-
it('preTransforms', () => {
319+
it('pre/post transforms', () => {
320320
const options = extend({}, baseOptions)
321-
const spy = jasmine.createSpy('preTransform')
321+
const spy1 = jasmine.createSpy('preTransform')
322+
const spy2 = jasmine.createSpy('postTransform')
322323
options.modules = options.modules.concat([{
323324
preTransformNode (el) {
324-
spy(el.tag)
325+
spy1(el.tag)
326+
},
327+
postTransformNode (el) {
328+
expect(el.staticAttrs.length).toBe(1)
329+
spy2(el.tag)
325330
}
326331
}])
327332
parse('<img v-pre src="hi">', options)
328-
expect(spy).toHaveBeenCalledWith('img')
333+
expect(spy1).toHaveBeenCalledWith('img')
334+
expect(spy2).toHaveBeenCalledWith('img')
329335
})
330336
})

0 commit comments

Comments
 (0)