|
1 | 1 | import type { ComponentResolver } from '../src'
|
2 | 2 | import { describe, expect, it } from 'vitest'
|
| 3 | +import { pascalCase } from '../src' |
3 | 4 | import { Context } from '../src/core/context'
|
4 | 5 |
|
5 | 6 | const resolver: ComponentResolver[] = [
|
@@ -173,3 +174,38 @@ describe('component and directive as same name', () => {
|
173 | 174 | expect(await ctx.transform(code, '')).toMatchSnapshot()
|
174 | 175 | })
|
175 | 176 | })
|
| 177 | + |
| 178 | +describe('prefix transform', () => { |
| 179 | + it('transform with prefix should work', async () => { |
| 180 | + const code = ` |
| 181 | + const render = (_ctx, _cache) => { |
| 182 | + const _component_test_comp = _resolveComponent("custom-prefix-test-comp") |
| 183 | + const _component_testComp = _resolveComponent("CustomPrefixTestComp") |
| 184 | + const _component_testComp = _resolveComponent("customPrefixTestComp") |
| 185 | +
|
| 186 | + return _withDirectives( |
| 187 | + (_openBlock(), |
| 188 | + _createBlock(_component_test_comp, null, null, 512 /* NEED_PATCH */)), |
| 189 | + _createBlock(_component_testComp, null, null, 512 /* NEED_PATCH */)), |
| 190 | + _createBlock(_component_TestComp, null, null, 512 /* NEED_PATCH */)) |
| 191 | + ) |
| 192 | + } |
| 193 | + ` |
| 194 | + |
| 195 | + const ctx = new Context({ |
| 196 | + prefix: 'CustomPrefix', |
| 197 | + directives: true, |
| 198 | + }) |
| 199 | + ctx.sourcemap = false |
| 200 | + const componentName = 'TestComp' |
| 201 | + const name = `${pascalCase(ctx.options.prefix)}${pascalCase(componentName)}` |
| 202 | + // @ts-expect-error for test |
| 203 | + ctx._componentNameMap = { |
| 204 | + [name]: { |
| 205 | + as: name, |
| 206 | + from: 'test/component/test-comp.vue', |
| 207 | + }, |
| 208 | + } |
| 209 | + expect(await ctx.transform(code, '')).toMatchSnapshot() |
| 210 | + }) |
| 211 | +}) |
0 commit comments