Skip to content

Commit ec4b0e9

Browse files
authored
Merge branch 'vuejs:main' into bwsy/transformElm
2 parents 4bed51a + 50e2253 commit ec4b0e9

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
727727
setup(__props, { expose, emit }) {
728728
expose();
729729

730-
const props = __props
730+
const props = __props;
731731

732732
const a = 1;
733733

packages/compiler-sfc/__tests__/compileTemplate.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,22 @@ test('should work', () => {
2222
expect(result.code).toMatch(`export function render(`)
2323
})
2424

25+
// #6807
26+
test('should work with style comment', () => {
27+
const source = `
28+
<div style="
29+
/* nothing */
30+
width: 300px;
31+
height: 100px/* nothing */
32+
">{{ render }}</div>
33+
`
34+
35+
const result = compile({ filename: 'example.vue', source })
36+
expect(result.errors.length).toBe(0)
37+
expect(result.source).toBe(source)
38+
expect(result.code).toMatch(`{"width":"300px","height":"100px"}`)
39+
})
40+
2541
test('preprocess pug', () => {
2642
const template = parse(
2743
`

packages/compiler-sfc/__tests__/parse.spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ h1 { color: red }
268268
})
269269

270270
test('treat custom blocks as raw text', () => {
271-
const { errors, descriptor } = parse(`<foo> <-& </foo>`)
271+
const { errors, descriptor } = parse(
272+
`<template><input></template><foo> <-& </foo>`
273+
)
272274
expect(errors.length).toBe(0)
273275
expect(descriptor.customBlocks[0].content).toBe(` <-& `)
274276
})
@@ -309,5 +311,13 @@ h1 { color: red }
309311
).errors.length
310312
).toBe(0)
311313
})
314+
315+
// # 6676
316+
test('should throw error if no <template> or <script> is present', () => {
317+
assertWarning(
318+
parse(`import { ref } from 'vue'`).errors,
319+
`At least one <template> or <script> is required in a single file component`
320+
)
321+
})
312322
})
313323
})

packages/compiler-sfc/src/parse.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ export function parse(
149149
errors.push(e)
150150
}
151151
})
152-
153152
ast.children.forEach(node => {
154153
if (node.type !== NodeTypes.ELEMENT) {
155154
return
@@ -218,7 +217,13 @@ export function parse(
218217
break
219218
}
220219
})
221-
220+
if (!descriptor.template && !descriptor.script && !descriptor.scriptSetup) {
221+
errors.push(
222+
new SyntaxError(
223+
`At least one <template> or <script> is required in a single file component.`
224+
)
225+
)
226+
}
222227
if (descriptor.scriptSetup) {
223228
if (descriptor.scriptSetup.src) {
224229
errors.push(

packages/shared/src/normalizeProp.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ export function normalizeStyle(
2828

2929
const listDelimiterRE = /;(?![^(]*\))/g
3030
const propertyDelimiterRE = /:([^]+)/
31+
const styleCommentRE = /\/\*.*?\*\//gs
3132

3233
export function parseStringStyle(cssText: string): NormalizedStyle {
3334
const ret: NormalizedStyle = {}
34-
cssText.split(listDelimiterRE).forEach(item => {
35-
if (item) {
36-
const tmp = item.split(propertyDelimiterRE)
37-
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())
38-
}
39-
})
35+
cssText
36+
.replace(styleCommentRE, '')
37+
.split(listDelimiterRE)
38+
.forEach(item => {
39+
if (item) {
40+
const tmp = item.split(propertyDelimiterRE)
41+
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())
42+
}
43+
})
4044
return ret
4145
}
4246

0 commit comments

Comments
 (0)