File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,26 @@ describe('compiler: transform', () => {
200
200
expect ( ( ast as any ) . children [ 0 ] . props [ 0 ] . exp . content ) . toBe ( `_hoisted_1` )
201
201
expect ( ( ast as any ) . children [ 1 ] . props [ 0 ] . exp . content ) . toBe ( `_hoisted_2` )
202
202
} )
203
+
204
+ test ( 'context.filename and selfName' , ( ) => {
205
+ const ast = baseParse ( `<div />` )
206
+
207
+ const calls : any [ ] = [ ]
208
+ const plugin : NodeTransform = ( node , context ) => {
209
+ calls . push ( { ...context } )
210
+ }
211
+
212
+ transform ( ast , {
213
+ filename : '/the/fileName.vue' ,
214
+ nodeTransforms : [ plugin ]
215
+ } )
216
+
217
+ expect ( calls . length ) . toBe ( 2 )
218
+ expect ( calls [ 1 ] ) . toMatchObject ( {
219
+ filename : '/the/fileName.vue' ,
220
+ selfName : 'FileName'
221
+ } )
222
+ } )
203
223
204
224
test ( 'onError option' , ( ) => {
205
225
const ast = baseParse ( `<div/>` )
Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ export interface ImportItem {
84
84
85
85
export interface TransformContext
86
86
extends Required <
87
- Omit < TransformOptions , 'filename' | keyof CompilerCompatOptions >
87
+ Omit < TransformOptions , keyof CompilerCompatOptions >
88
88
> ,
89
89
CompilerCompatOptions {
90
90
selfName : string | null
@@ -153,6 +153,7 @@ export function createTransformContext(
153
153
const nameMatch = filename . replace ( / \? .* $ / , '' ) . match ( / ( [ ^ / \\ ] + ) \. \w + $ / )
154
154
const context : TransformContext = {
155
155
// options
156
+ filename,
156
157
selfName : nameMatch && capitalize ( camelize ( nameMatch [ 1 ] ) ) ,
157
158
prefixIdentifiers,
158
159
hoistStatic,
You can’t perform that action at this time.
0 commit comments