From acec23207e312bd2b6e9cbb93b51c8b595161c80 Mon Sep 17 00:00:00 2001 From: Qiyu8 Date: Mon, 19 Aug 2019 20:24:36 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=20issue=204203,=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=9C=BA=E5=88=B6=EF=BC=8C=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E4=BB=8E=E5=8D=8A=E4=B8=AA=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=B38=E5=88=86=E9=92=9F=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taroize/src/cache.ts | 14 ++++++++++++++ packages/taroize/src/wxml.ts | 24 ++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 packages/taroize/src/cache.ts diff --git a/packages/taroize/src/cache.ts b/packages/taroize/src/cache.ts new file mode 100644 index 000000000000..57351f72f22a --- /dev/null +++ b/packages/taroize/src/cache.ts @@ -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) { + return + } + cacheMap.set(dirpath, cloneDeep(wxml)) +} \ No newline at end of file diff --git a/packages/taroize/src/wxml.ts b/packages/taroize/src/wxml.ts index a646d9cc66ed..6845c819722d 100644 --- a/packages/taroize/src/wxml.ts +++ b/packages/taroize/src/wxml.ts @@ -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 +} + 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 -} { +export function parseWXML (dirPath: string, wxml?: string, parseImport?: boolean): Wxml { + let parseResult: Wxml = getCacheWxml(dirPath) + 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, imports: Imports[]): WXS { From 413b74224b1d107ce949243442f0dd845a8a4394 Mon Sep 17 00:00:00 2001 From: Qiyu8 Date: Mon, 26 Aug 2019 18:50:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix4203=201.Map=E5=A2=9E=E5=8A=A0=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AE=9A=E4=B9=89=202.=E5=8E=BB=E9=99=A4dirPath?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taroize/src/cache.ts | 11 ++++------- packages/taroize/src/wxml.ts | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/taroize/src/cache.ts b/packages/taroize/src/cache.ts index 57351f72f22a..232165e3ab2a 100644 --- a/packages/taroize/src/cache.ts +++ b/packages/taroize/src/cache.ts @@ -1,14 +1,11 @@ import { Wxml } from './wxml' import { cloneDeep } from 'lodash' -const cacheMap = new Map() +const cacheMap = new Map() - export function getCacheWxml(dirpath: string): Wxml { +export function getCacheWxml(dirpath: string): Wxml | undefined { return cloneDeep(cacheMap.get(dirpath)) } - export function saveCacheWxml(dirpath: string, wxml: Wxml) { - if (!dirpath) { - return - } +export function saveCacheWxml(dirpath: string, wxml: Wxml) { cacheMap.set(dirpath, cloneDeep(wxml)) -} \ No newline at end of file +} \ No newline at end of file diff --git a/packages/taroize/src/wxml.ts b/packages/taroize/src/wxml.ts index 646b7d9367db..15b7cd3c310d 100644 --- a/packages/taroize/src/wxml.ts +++ b/packages/taroize/src/wxml.ts @@ -302,7 +302,7 @@ export const createWxmlVistor = ( } export function parseWXML (dirPath: string, wxml?: string, parseImport?: boolean): Wxml { - let parseResult: Wxml = getCacheWxml(dirPath) + let parseResult = getCacheWxml(dirPath) if (parseResult) { return parseResult }