Skip to content

Commit

Permalink
refactor(transformer): 除了 div 和 text 之外的所有快应用组件: style -> customstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Jul 30, 2019
1 parent a58f2ec commit 0d865dc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/taro-transformer-wx/src/create-html-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface Options {
value: string
}

function stringifyAttributes (input: object) {
function stringifyAttributes (input: object, componentName: string) {
const attributes: string[] = []

for (const key of Object.keys(input)) {
Expand All @@ -37,6 +37,10 @@ function stringifyAttributes (input: object) {

let attribute = key

if (Adapters.quickapp === Adapter.type && !['div', 'text'].includes(componentName) && key === 'style') {
attribute = 'customstyle'
}

if (value !== true) {
attribute += `="${String(value)}"`
}
Expand Down Expand Up @@ -78,7 +82,7 @@ export const createHTMLElement = (options: Options, isFirstEmit = false) => {

const isVoidTag = voidHtmlTags.has(options.name)

let ret = `<${options.name}${stringifyAttributes(options.attributes)}${isVoidTag ? `/` : '' }>`
let ret = `<${options.name}${stringifyAttributes(options.attributes, options.name)}${isVoidTag ? `/` : '' }>`

if (!isVoidTag) {
ret += `${options.value}</${options.name}>`
Expand Down

0 comments on commit 0d865dc

Please sign in to comment.