Skip to content

Commit

Permalink
Merge branch 'vuejs:main' into bwsy/transformElm
Browse files Browse the repository at this point in the history
  • Loading branch information
baiwusanyu-c authored Nov 8, 2022
2 parents 4bed51a + 50e2253 commit ec4b0e9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
setup(__props, { expose, emit }) {
expose();

const props = __props
const props = __props;

const a = 1;

Expand Down
16 changes: 16 additions & 0 deletions packages/compiler-sfc/__tests__/compileTemplate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ test('should work', () => {
expect(result.code).toMatch(`export function render(`)
})

// #6807
test('should work with style comment', () => {
const source = `
<div style="
/* nothing */
width: 300px;
height: 100px/* nothing */
">{{ render }}</div>
`

const result = compile({ filename: 'example.vue', source })
expect(result.errors.length).toBe(0)
expect(result.source).toBe(source)
expect(result.code).toMatch(`{"width":"300px","height":"100px"}`)
})

test('preprocess pug', () => {
const template = parse(
`
Expand Down
12 changes: 11 additions & 1 deletion packages/compiler-sfc/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ h1 { color: red }
})

test('treat custom blocks as raw text', () => {
const { errors, descriptor } = parse(`<foo> <-& </foo>`)
const { errors, descriptor } = parse(
`<template><input></template><foo> <-& </foo>`
)
expect(errors.length).toBe(0)
expect(descriptor.customBlocks[0].content).toBe(` <-& `)
})
Expand Down Expand Up @@ -309,5 +311,13 @@ h1 { color: red }
).errors.length
).toBe(0)
})

// # 6676
test('should throw error if no <template> or <script> is present', () => {
assertWarning(
parse(`import { ref } from 'vue'`).errors,
`At least one <template> or <script> is required in a single file component`
)
})
})
})
9 changes: 7 additions & 2 deletions packages/compiler-sfc/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export function parse(
errors.push(e)
}
})

ast.children.forEach(node => {
if (node.type !== NodeTypes.ELEMENT) {
return
Expand Down Expand Up @@ -218,7 +217,13 @@ export function parse(
break
}
})

if (!descriptor.template && !descriptor.script && !descriptor.scriptSetup) {
errors.push(
new SyntaxError(
`At least one <template> or <script> is required in a single file component.`
)
)
}
if (descriptor.scriptSetup) {
if (descriptor.scriptSetup.src) {
errors.push(
Expand Down
16 changes: 10 additions & 6 deletions packages/shared/src/normalizeProp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ export function normalizeStyle(

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

export function parseStringStyle(cssText: string): NormalizedStyle {
const ret: NormalizedStyle = {}
cssText.split(listDelimiterRE).forEach(item => {
if (item) {
const tmp = item.split(propertyDelimiterRE)
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())
}
})
cssText
.replace(styleCommentRE, '')
.split(listDelimiterRE)
.forEach(item => {
if (item) {
const tmp = item.split(propertyDelimiterRE)
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim())
}
})
return ret
}

Expand Down

0 comments on commit ec4b0e9

Please sign in to comment.