-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix issue 4203,加入缓存机制,转换时间从半个小时优化至8分钟内 #4216
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Wxml } from './wxml' | ||
import { cloneDeep } from 'lodash' | ||
const cacheMap = new Map() | ||
|
||
export function getCacheWxml(dirpath: string): Wxml { | ||
return cloneDeep(cacheMap.get(dirpath)) | ||
} | ||
|
||
export function saveCacheWxml(dirpath: string, wxml: Wxml) { | ||
if (!dirpath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里 dirpath 应该一直都有才对? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 嗯,dirpath是不会为空的 |
||
return | ||
} | ||
cacheMap.set(dirpath, cloneDeep(wxml)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { parseTemplate, parseModule } from './template' | |
import { usedComponents, errors, globals, THIRD_PARTY_COMPONENTS } from './global' | ||
import { reserveKeyWords } from './constant' | ||
import { parse as parseFile } from 'babylon' | ||
import { getCacheWxml, saveCacheWxml } from './cache' | ||
const { prettyPrint } = require('html') | ||
|
||
const allCamelCase = (str: string) => | ||
|
@@ -70,6 +71,13 @@ export interface Imports { | |
wxs?: boolean | ||
} | ||
|
||
export interface Wxml { | ||
wxses: WXS[] | ||
wxml?: t.Node | ||
imports: Imports[] | ||
refIds: Set<string> | ||
} | ||
|
||
const WX_IF = 'wx:if' | ||
const WX_ELSE_IF = 'wx:elif' | ||
const WX_FOR = 'wx:for' | ||
|
@@ -293,12 +301,11 @@ export const createWxmlVistor = ( | |
} as Visitor | ||
} | ||
|
||
export function parseWXML (dirPath: string, wxml?: string, parseImport?: boolean): { | ||
wxses: WXS[] | ||
wxml?: t.Node | ||
imports: Imports[] | ||
refIds: Set<string> | ||
} { | ||
export function parseWXML (dirPath: string, wxml?: string, parseImport?: boolean): Wxml { | ||
let parseResult: Wxml = getCacheWxml(dirPath) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getCacheWxml是可能返回undefined |
||
if (parseResult) { | ||
return parseResult | ||
} | ||
try { | ||
wxml = prettyPrint(wxml, { | ||
max_char: 0, | ||
|
@@ -343,13 +350,14 @@ export function parseWXML (dirPath: string, wxml?: string, parseImport?: boolean | |
refIds.delete(id) | ||
} | ||
}) | ||
|
||
return { | ||
parseResult = { | ||
wxses, | ||
imports, | ||
wxml: hydrate(ast), | ||
refIds | ||
} | ||
saveCacheWxml(dirPath, parseResult) | ||
return parseResult | ||
} | ||
|
||
function getWXS (attrs: t.JSXAttribute[], path: NodePath<t.JSXElement>, imports: Imports[]): WXS { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里最好把 Map 的泛型签名写一下。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已指定类型