]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): assest id (#190)
author月迷津渡 <CodeDaraW@gmail.com>
Thu, 10 Oct 2019 17:55:26 +0000 (01:55 +0800)
committerEvan You <yyx990803@gmail.com>
Thu, 10 Oct 2019 17:55:26 +0000 (13:55 -0400)
* fix(compile-core): asset id

* test(compile-core): asset id

packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap
packages/compiler-core/__tests__/codegen.spec.ts
packages/compiler-core/src/utils.ts

index 9f8a5b6f4504bbbef5d97d40dc8cc0f8781e8804..412311cb139238958270ea7466efa098a4bf8b6f 100644 (file)
@@ -54,7 +54,8 @@ exports[`compiler: codegen assets 1`] = `
 return function render() {
   with (this) {
     const _component_Foo = _resolveComponent(\\"Foo\\")
-    const _component_barbaz = _resolveComponent(\\"bar-baz\\")
+    const _component_bar_baz = _resolveComponent(\\"bar-baz\\")
+    const _component_barbaz = _resolveComponent(\\"barbaz\\")
     const _directive_my_dir = _resolveDirective(\\"my_dir\\")
     
     return null
index 48a89c41572835043558ab7e02132e6a5d508c11..d2eace424a932c4485a836fbf1625930f6aa04de 100644 (file)
@@ -89,7 +89,7 @@ describe('compiler: codegen', () => {
 
   test('assets', () => {
     const root = createRoot({
-      components: [`Foo`, `bar-baz`],
+      components: [`Foo`, `bar-baz`, `barbaz`],
       directives: [`my_dir`]
     })
     const { code } = generate(root, { mode: 'function' })
@@ -97,10 +97,15 @@ describe('compiler: codegen', () => {
       `const _component_Foo = _${helperNameMap[RESOLVE_COMPONENT]}("Foo")\n`
     )
     expect(code).toMatch(
-      `const _component_barbaz = _${
+      `const _component_bar_baz = _${
         helperNameMap[RESOLVE_COMPONENT]
       }("bar-baz")\n`
     )
+    expect(code).toMatch(
+      `const _component_barbaz = _${
+        helperNameMap[RESOLVE_COMPONENT]
+      }("barbaz")\n`
+    )
     expect(code).toMatch(
       `const _directive_my_dir = _${
         helperNameMap[RESOLVE_DIRECTIVE]
index 0f873e3ac3471940f5bcb553a6437d2e001f4dbc..d78208745ce939b8a80f4ec93229cf3016cb1782 100644 (file)
@@ -241,7 +241,7 @@ export function toValidAssetId(
   name: string,
   type: 'component' | 'directive'
 ): string {
-  return `_${type}_${name.replace(/[^\w]/g, '')}`
+  return `_${type}_${name.replace(/[^\w]/g, '_')}`
 }
 
 export function isEmptyExpression(node: ExpressionNode) {