feat(compiler-sfc): properly pass on options

This commit is contained in:
Evan You
2019-12-10 12:22:23 -05:00
parent 0a14c04c81
commit c8c5b16ef7
5 changed files with 406 additions and 20 deletions

View File

@@ -13,7 +13,7 @@ export interface AssetURLOptions {
[name: string]: string[]
}
const assetURLOptions: AssetURLOptions = {
const defaultOptions: AssetURLOptions = {
video: ['src', 'poster'],
source: ['src'],
img: ['src'],
@@ -21,11 +21,26 @@ const assetURLOptions: AssetURLOptions = {
use: ['xlink:href', 'href']
}
export const transformAssetUrl: NodeTransform = (node, context) => {
export const createAssetUrlTransformWithOptions = (
options: AssetURLOptions
): NodeTransform => {
const mergedOptions = {
...defaultOptions,
...options
}
return (node, context) =>
(transformAssetUrl as Function)(node, context, mergedOptions)
}
export const transformAssetUrl: NodeTransform = (
node,
context,
options: AssetURLOptions = defaultOptions
) => {
if (node.type === NodeTypes.ELEMENT) {
for (const tag in assetURLOptions) {
for (const tag in options) {
if ((tag === '*' || node.tag === tag) && node.props.length) {
const attributes = assetURLOptions[tag]
const attributes = options[tag]
attributes.forEach(item => {
node.props.forEach((attr: AttributeNode, index) => {
if (attr.type !== NodeTypes.ATTRIBUTE) return