diff --git a/packages/compiler-core/__tests__/transform.spec.ts b/packages/compiler-core/__tests__/transform.spec.ts index 042865efb4e..f316a671e07 100644 --- a/packages/compiler-core/__tests__/transform.spec.ts +++ b/packages/compiler-core/__tests__/transform.spec.ts @@ -200,6 +200,26 @@ describe('compiler: transform', () => { expect((ast as any).children[0].props[0].exp.content).toBe(`_hoisted_1`) expect((ast as any).children[1].props[0].exp.content).toBe(`_hoisted_2`) }) + + test('context.filename and selfName', () => { + const ast = baseParse(`
`) + + const calls: any[] = [] + const plugin: NodeTransform = (node, context) => { + calls.push({ ...context }) + } + + transform(ast, { + filename: '/the/fileName.vue', + nodeTransforms: [plugin] + }) + + expect(calls.length).toBe(2) + expect(calls[1]).toMatchObject({ + filename: '/the/fileName.vue', + selfName: 'FileName' + }) + }) test('onError option', () => { const ast = baseParse(`
`) diff --git a/packages/compiler-core/src/transform.ts b/packages/compiler-core/src/transform.ts index 4d9e8c6ed49..e308accef79 100644 --- a/packages/compiler-core/src/transform.ts +++ b/packages/compiler-core/src/transform.ts @@ -84,7 +84,7 @@ export interface ImportItem { export interface TransformContext extends Required< - Omit + Omit >, CompilerCompatOptions { selfName: string | null @@ -152,6 +152,7 @@ export function createTransformContext( const nameMatch = filename.replace(/\?.*$/, '').match(/([^/\\]+)\.\w+$/) const context: TransformContext = { // options + filename, selfName: nameMatch && capitalize(camelize(nameMatch[1])), prefixIdentifiers, hoistStatic,