|
|
@@ -22,10 +22,11 @@ export function parseComponent (
|
|
|
const sfc: SFCDescriptor = {
|
|
|
template: null,
|
|
|
script: null,
|
|
|
- styles: []
|
|
|
+ styles: [],
|
|
|
+ customBlocks: []
|
|
|
}
|
|
|
let depth = 0
|
|
|
- let currentBlock: ?SFCBlock = null
|
|
|
+ let currentBlock: ?(SFCBlock | SFCCustomBlock) = null
|
|
|
|
|
|
function start (
|
|
|
tag: string,
|
|
|
@@ -34,17 +35,30 @@ export function parseComponent (
|
|
|
start: number,
|
|
|
end: number
|
|
|
) {
|
|
|
- if (isSpecialTag(tag) && depth === 0) {
|
|
|
- currentBlock = {
|
|
|
- type: tag,
|
|
|
- content: '',
|
|
|
- start: end
|
|
|
- }
|
|
|
- checkAttrs(currentBlock, attrs)
|
|
|
- if (tag === 'style') {
|
|
|
- sfc.styles.push(currentBlock)
|
|
|
- } else {
|
|
|
- sfc[tag] = currentBlock
|
|
|
+ if (depth === 0) {
|
|
|
+ if (isSpecialTag(tag)) {
|
|
|
+ currentBlock = {
|
|
|
+ type: tag,
|
|
|
+ content: '',
|
|
|
+ start: end
|
|
|
+ }
|
|
|
+ checkAttrs(currentBlock, attrs)
|
|
|
+ if (tag === 'style') {
|
|
|
+ sfc.styles.push(currentBlock)
|
|
|
+ } else {
|
|
|
+ sfc[tag] = currentBlock
|
|
|
+ }
|
|
|
+ } else { // custom blocks
|
|
|
+ currentBlock = {
|
|
|
+ type: tag,
|
|
|
+ content: '',
|
|
|
+ start: end,
|
|
|
+ attrs: attrs.reduce((cumulated, { name, value }) => {
|
|
|
+ cumulated[name] = value
|
|
|
+ return cumulated
|
|
|
+ }, Object.create(null))
|
|
|
+ }
|
|
|
+ sfc.customBlocks.push(currentBlock)
|
|
|
}
|
|
|
}
|
|
|
if (!unary) {
|
|
|
@@ -71,7 +85,7 @@ export function parseComponent (
|
|
|
}
|
|
|
|
|
|
function end (tag: string, start: number, end: number) {
|
|
|
- if (isSpecialTag(tag) && depth === 1 && currentBlock) {
|
|
|
+ if (depth === 1 && currentBlock) {
|
|
|
currentBlock.end = start
|
|
|
let text = deindent(content.slice(currentBlock.start, currentBlock.end))
|
|
|
// pad content so that linters and pre-processors can output correct
|
|
|
@@ -85,7 +99,7 @@ export function parseComponent (
|
|
|
depth--
|
|
|
}
|
|
|
|
|
|
- function padContent (block: SFCBlock) {
|
|
|
+ function padContent (block: SFCBlock | SFCCustomBlock) {
|
|
|
const offset = content.slice(0, block.start).split(splitRE).length
|
|
|
const padChar = block.type === 'script' && !block.lang
|
|
|
? '//\n'
|