Skip to content

Commit bee95f8

Browse files
committed
Revert "remove parser pre/post transforms (not used)"
This reverts commit 2e7a792.
1 parent 74f8b98 commit bee95f8

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/compiler/parser/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const decodeHTMLCached = cached(decodeHTML)
3030
let warn
3131
let platformGetTagNamespace
3232
let platformMustUseProp
33+
let preTransforms
3334
let transforms
35+
let postTransforms
3436
let 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 () {

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

+18
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)