Quellcode durchsuchen

fix(compiler-sfc): expose src on custom blocks as well

Evan You vor 4 Jahren
Ursprung
Commit
cdfc4c134d

+ 5 - 3
packages/compiler-sfc/src/parseComponent.ts

@@ -125,6 +125,11 @@ export function parseComponent(
           return cumulated
         }, {})
       }
+
+      if (typeof currentBlock.attrs.src === 'string') {
+        currentBlock.src = currentBlock.attrs.src
+      }
+
       if (isSpecialTag(tag)) {
         checkAttrs(currentBlock, attrs)
         if (tag === 'script') {
@@ -162,9 +167,6 @@ export function parseComponent(
       if (attr.name === 'module') {
         block.module = attr.value || true
       }
-      if (attr.name === 'src') {
-        block.src = attr.value
-      }
     }
   }
 

+ 5 - 1
packages/compiler-sfc/test/parseComponent.spec.ts

@@ -202,10 +202,11 @@ describe('Single File Component parser', () => {
         }))
       }
       </test>
+      <custom src="./x.json"></custom>
     `,
       { deindent: true }
     )
-    expect(res.customBlocks.length).toBe(3)
+    expect(res.customBlocks.length).toBe(4)
 
     const simpleExample = res.customBlocks[0]
     expect(simpleExample.type).toBe('example')
@@ -233,6 +234,9 @@ describe('Single File Component parser', () => {
 }`)
     expect(simpleTest.attrs.name).toBe('simple')
     expect(simpleTest.attrs.foo).toBe('bar')
+
+    const customWithSrc = res.customBlocks[3]
+    expect(customWithSrc.src).toBe('./x.json')
   })
 
   // Regression #4289