mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
refactor: use existing types
This commit is contained in:
parent
06594f68b7
commit
ed4bbed990
@ -1,6 +1,7 @@
|
||||
// vue compiler module for transforming `<tag>:<attribute>` to `require`
|
||||
|
||||
import { urlToRequire, ASTNode, Attr } from './utils'
|
||||
import { urlToRequire } from './utils'
|
||||
import { ASTNode, ASTAttr } from 'types/compiler'
|
||||
|
||||
export interface AssetURLOptions {
|
||||
[name: string]: string | string[]
|
||||
@ -43,16 +44,19 @@ function transform(
|
||||
options: AssetURLOptions,
|
||||
transformAssetUrlsOption?: TransformAssetUrlsOptions
|
||||
) {
|
||||
if (node.type !== 1 || !node.attrs) return
|
||||
for (const tag in options) {
|
||||
if ((tag === '*' || node.tag === tag) && node.attrs) {
|
||||
if (tag === '*' || node.tag === tag) {
|
||||
const attributes = options[tag]
|
||||
if (typeof attributes === 'string') {
|
||||
node.attrs.some(attr =>
|
||||
node.attrs!.some(attr =>
|
||||
rewrite(attr, attributes, transformAssetUrlsOption)
|
||||
)
|
||||
} else if (Array.isArray(attributes)) {
|
||||
attributes.forEach(item =>
|
||||
node.attrs.some(attr => rewrite(attr, item, transformAssetUrlsOption))
|
||||
node.attrs!.some(attr =>
|
||||
rewrite(attr, item, transformAssetUrlsOption)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -60,7 +64,7 @@ function transform(
|
||||
}
|
||||
|
||||
function rewrite(
|
||||
attr: Attr,
|
||||
attr: ASTAttr,
|
||||
name: string,
|
||||
transformAssetUrlsOption?: TransformAssetUrlsOptions
|
||||
) {
|
||||
|
@ -1,7 +1,8 @@
|
||||
// vue compiler module for transforming `img:srcset` to a number of `require`s
|
||||
|
||||
import { urlToRequire, ASTNode } from './utils'
|
||||
import { urlToRequire } from './utils'
|
||||
import { TransformAssetUrlsOptions } from './assetUrl'
|
||||
import { ASTNode } from 'types/compiler'
|
||||
|
||||
interface ImageCandidate {
|
||||
require: string
|
||||
@ -21,9 +22,11 @@ function transform(
|
||||
node: ASTNode,
|
||||
transformAssetUrlsOptions?: TransformAssetUrlsOptions
|
||||
) {
|
||||
const tags = ['img', 'source']
|
||||
if (node.type !== 1 || !node.attrs) {
|
||||
return
|
||||
}
|
||||
|
||||
if (tags.indexOf(node.tag) !== -1 && node.attrs) {
|
||||
if (node.tag === 'img' || node.tag === 'source') {
|
||||
node.attrs.forEach(attr => {
|
||||
if (attr.name === 'srcset') {
|
||||
// same logic as in transform-require.js
|
||||
|
@ -2,16 +2,6 @@ import { TransformAssetUrlsOptions } from './assetUrl'
|
||||
import { UrlWithStringQuery, parse as uriParse } from 'url'
|
||||
import path from 'path'
|
||||
|
||||
export interface Attr {
|
||||
name: string
|
||||
value: string
|
||||
}
|
||||
|
||||
export interface ASTNode {
|
||||
tag: string
|
||||
attrs: Attr[]
|
||||
}
|
||||
|
||||
export function urlToRequire(
|
||||
url: string,
|
||||
transformAssetUrlsOption: TransformAssetUrlsOptions = {}
|
||||
|
@ -4,7 +4,6 @@ import { compileTemplate } from '../src/compileTemplate'
|
||||
import Vue from 'vue'
|
||||
|
||||
function mockRender(code: string, mocks: Record<string, any> = {}) {
|
||||
console.log(code)
|
||||
const fn = new Function(
|
||||
`require`,
|
||||
`${code}; return { render, staticRenderFns }`
|
||||
|
Loading…
Reference in New Issue
Block a user