提交 5e2598a9 编写于 作者: fxy060608's avatar fxy060608

feat(x-android): 支持 pug

上级 af26cffc
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`SFC compile template template with html 1`] = `
"const msg = ''
export default {
setup(__props: GenAnonymous) {
const __ins = getCurrentInstance()!;
const _ctx = __ins.proxy as GenAnonymous;
const _cache = __ins.renderCache;
return
function GenAnonymousRender(): any | null {
return createElementVNode("view", utsMapOf({ class: "test" }))
}
}
}"
`;
exports[`SFC compile template template with pug 1`] = `
"const msg = ''
export default {
setup(__props: GenAnonymous) {
const __ins = getCurrentInstance()!;
const _ctx = __ins.proxy as GenAnonymous;
const _cache = __ins.renderCache;
return
function GenAnonymousRender(): any | null {
return createElementVNode("view", utsMapOf({ class: "test" }))
}
}
}"
`;
import { compileSFCScript as compile, assertCode } from './utils'
describe('SFC compile template', () => {
test('template with html', () => {
const { content } = compile(
`<script setup>const msg = ''</script><template lang='html'><view class="test"/></template>`,
{ inlineTemplate: true }
)
assertCode(content)
})
test('template with pug', () => {
const { content } = compile(
`<script setup>const msg = ''</script><template lang='pug'>view.test</template>`,
{ inlineTemplate: true }
)
assertCode(content)
})
})
......@@ -7,6 +7,7 @@ import {
} from '../../../src/plugins/android/uvue/sfc/compiler/compileScript'
import { genTemplateCode } from '../../../src/plugins/android/uvue/code/template'
import { resolveGenTemplateCodeOptions } from '../../../src/plugins/android/uvue/sfc/template'
export const mockId = 'xxxxxxxx'
export function compileSFCScript(
......@@ -34,6 +35,7 @@ export function compileSFCScript(
className,
sourceMap: false,
bindingMetadata: result.bindings,
preprocessLang: descriptor.template?.lang,
})
)
result.content = result.content.replace(
......
......@@ -30,6 +30,7 @@
"@vue/compiler-core": "3.3.11",
"@vue/compiler-dom": "3.3.11",
"@vue/compiler-sfc": "3.3.11",
"@vue/consolidate": "^1.0.0",
"@vue/shared": "3.3.11",
"debug": "^4.3.3",
"es-module-lexer": "^1.2.1",
......@@ -42,6 +43,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.7",
"@types/fs-extra": "^9.0.13"
"@types/fs-extra": "^9.0.13",
"pug": "^3.0.2"
}
}
import { SFCDescriptor } from '@vue/compiler-sfc'
import consolidate from '@vue/consolidate'
import { compile } from '../compiler'
import { TemplateCompilerOptions } from '../compiler/options'
import { genRenderFunctionDecl } from '../compiler/utils'
......@@ -20,7 +21,57 @@ export function genTemplate(
imports: [],
}
}
return compile(template.content, options)
const { preprocessLang, preprocessOptions } = options
const preprocessor = preprocessLang
? (consolidate[preprocessLang as keyof typeof consolidate] as
| PreProcessor
| undefined)
: false
return compile(
preprocessor
? preprocess(
{ source: template.content, filename: '', preprocessOptions },
preprocessor
)
: template.content,
options
)
}
export const genTemplateCode = genTemplate
interface PreProcessor {
render(
source: string,
options: any,
cb: (err: Error | null, res: string) => void
): void
}
function preprocess(
{
source,
filename,
preprocessOptions,
}: { source: string; filename: string; preprocessOptions: any },
preprocessor: PreProcessor
): string {
// Consolidate exposes a callback based API, but the callback is in fact
// called synchronously for most templating engines. In our case, we have to
// expose a synchronous API so that it is usable in Jest transforms (which
// have to be sync because they are applied via Node.js require hooks)
let res: string = ''
let err: Error | null = null
preprocessor.render(
source,
{ filename, ...preprocessOptions },
(_err, _res) => {
if (_err) err = _err
res = _res
}
)
if (err) throw err
return res
}
......@@ -134,6 +134,9 @@ export type TemplateCompilerOptions = {
* e.g. platform native elements, e.g. `<div>` for browsers
*/
isNativeTag?: (tag: string) => boolean
preprocessLang?: string
preprocessOptions?: any
} & TransformOptions &
CodegenOptions
......
......@@ -29,6 +29,8 @@ export function resolveGenTemplateCodeOptions(
className: string
sourceMap: boolean
bindingMetadata?: BindingMetadata
preprocessLang?: string
preprocessOptions?: any
}
): TemplateCompilerOptions {
const inputRoot = normalizePath(options.rootDir)
......
......@@ -400,6 +400,9 @@ importers:
'@vue/compiler-sfc':
specifier: 3.3.11
version: 3.3.11
'@vue/consolidate':
specifier: ^1.0.0
version: 1.0.0
'@vue/shared':
specifier: 3.3.11
version: 3.3.11
......@@ -434,6 +437,9 @@ importers:
'@types/fs-extra':
specifier: ^9.0.13
version: 9.0.13
pug:
specifier: ^3.0.2
version: 3.0.2
packages/uni-app-vite:
dependencies:
......@@ -4918,6 +4924,11 @@ packages:
'@vue/compiler-dom': 3.3.11
'@vue/shared': 3.3.11
/@vue/consolidate@1.0.0:
resolution: {integrity: sha512-oTyUE+QHIzLw2PpV14GD/c7EohDyP64xCniWTcqcEmTd699eFqTIwOmtDYjcO1j3QgdXoJEoWv1/cCdLrRoOfg==}
engines: {node: '>= 0.12.0'}
dev: false
/@vue/devtools-api@6.5.0:
resolution: {integrity: sha512-o9KfBeaBmCKl10usN4crU53fYtC1r7jJwdGKjPT24t348rHxgfpZ0xL3Xm/gLUYnc0oTp8LAmrxOeLyu6tbk2Q==}
......@@ -5019,7 +5030,6 @@ packages:
resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==}
engines: {node: '>=0.4.0'}
hasBin: true
dev: false
/acorn@8.11.2:
resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==}
......@@ -5138,6 +5148,10 @@ packages:
engines: {node: '>=8'}
dev: true
/asap@2.0.6:
resolution: {integrity: sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==}
dev: true
/asn1.js@5.4.1:
resolution: {integrity: sha512-+I//4cYPccV8LdmBLiX8CYvf9Sp3vQsrqu2QNXRcrbiWvcx/UdlFiqUJJzxRQxgsZmvhXhn4cSKeSmoFjVdupA==}
dependencies:
......@@ -5153,6 +5167,10 @@ packages:
safer-buffer: 2.1.2
dev: true
/assert-never@1.2.1:
resolution: {integrity: sha512-TaTivMB6pYI1kXwrFlEhLeGfOqoDNdTxjCdwRfFFkEA30Eu+k48W34nlok2EYWJfFFzqaEmichdNM7th6M5HNw==}
dev: true
/assert-plus@1.0.0:
resolution: {integrity: sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==}
engines: {node: '>=0.8'}
......@@ -5341,6 +5359,13 @@ packages:
babel-preset-current-node-syntax: 1.0.1(@babel/core@7.21.3)
dev: true
/babel-walk@3.0.0-canary-5:
resolution: {integrity: sha512-GAwkz0AihzY5bkwIY5QDR+LvsRQgB/B+1foMPvi0FZPMl5fjD7ICiznUiBdLYMH1QYe6vqu4gWYytZOccLouFw==}
engines: {node: '>= 10.0.0'}
dependencies:
'@babel/types': 7.21.5
dev: true
/balanced-match@1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
......@@ -5611,6 +5636,12 @@ packages:
resolution: {integrity: sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==}
engines: {node: '>=10'}
/character-parser@2.2.0:
resolution: {integrity: sha512-+UqJQjFEFaTAs3bNsF2j2kEN1baG/zghZbdqoYEDxGZtJo9LBzl1A+m0D4n3qKx8N2FNv8/Xp6yV9mQmBuptaw==}
dependencies:
is-regex: 1.1.4
dev: true
/check-more-types@2.24.0:
resolution: {integrity: sha512-Pj779qHxV2tuapviy1bSZNEL1maXr13bPYpsvSDB68HlYcYuhlDrmGd63i0JHMCLKzc7rUSNIrpdJlhVlNwrxA==}
engines: {node: '>= 0.8.0'}
......@@ -5813,6 +5844,13 @@ packages:
typedarray: 0.0.6
dev: true
/constantinople@4.0.1:
resolution: {integrity: sha512-vCrqcSIq4//Gx74TXXCGnHpulY1dskqLTFGDmhrGxzeXL8lF8kvXv6mpNWlJj1uD4DW23D4ljAqbY4RRaaUZIw==}
dependencies:
'@babel/parser': 7.23.6
'@babel/types': 7.21.5
dev: true
/content-disposition@0.5.3:
resolution: {integrity: sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==}
engines: {node: '>= 0.6'}
......@@ -6234,6 +6272,10 @@ packages:
esutils: 2.0.3
dev: true
/doctypes@1.1.0:
resolution: {integrity: sha512-LLBi6pEqS6Do3EKQ3J0NqHWV5hhb78Pi8vvESYwyOy2c31ZEZVdtitdzsQsKb7878PEERhzUk0ftqGhG6Mz+pQ==}
dev: true
/dom-walk@0.1.2:
resolution: {integrity: sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w==}
dev: false
......@@ -7089,6 +7131,13 @@ packages:
engines: {node: '>= 0.4'}
dev: true
/has-tostringtag@1.0.2:
resolution: {integrity: sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==}
engines: {node: '>= 0.4'}
dependencies:
has-symbols: 1.0.3
dev: true
/has@1.0.3:
resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==}
engines: {node: '>= 0.4.0'}
......@@ -7344,6 +7393,13 @@ packages:
hasBin: true
dev: false
/is-expression@4.0.0:
resolution: {integrity: sha512-zMIXX63sxzG3XrkHkrAPvm/OVZVSCPNkwMHU8oTX7/U3AL78I0QXCEICXUM13BIa8TYGZ68PiTKfQz3yaTNr4A==}
dependencies:
acorn: 7.4.1
object-assign: 4.1.1
dev: true
/is-extglob@2.1.1:
resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
engines: {node: '>=0.10.0'}
......@@ -7400,12 +7456,24 @@ packages:
resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==}
dev: false
/is-promise@2.2.2:
resolution: {integrity: sha512-+lP4/6lKUBfQjZ2pdxThZvLUAafmZb8OAxFb8XXtiQmS35INgr85hdOGoEs124ez1FCnZJt6jau/T+alh58QFQ==}
dev: true
/is-reference@1.2.1:
resolution: {integrity: sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==}
dependencies:
'@types/estree': 0.0.51
dev: true
/is-regex@1.1.4:
resolution: {integrity: sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==}
engines: {node: '>= 0.4'}
dependencies:
call-bind: 1.0.2
has-tostringtag: 1.0.2
dev: true
/is-regexp@1.0.0:
resolution: {integrity: sha512-7zjFAPO4/gwyQAAgRRmqeEeyIICSdmCqa3tsVHMdBzaXXRiqopZL4Cyghg/XulGWrtABTpbnYYzzIRffLkP4oA==}
engines: {node: '>=0.10.0'}
......@@ -8397,6 +8465,10 @@ packages:
resolution: {integrity: sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==}
dev: true
/js-stringify@1.0.2:
resolution: {integrity: sha512-rtS5ATOo2Q5k1G+DADISilDA6lv79zIiwFd6CcjuIxGKLFm5C+RLImRscVap9k55i+MOZwgliw+NejvkLuGD5g==}
dev: true
/js-tokens@4.0.0:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
......@@ -8531,6 +8603,13 @@ packages:
verror: 1.10.0
dev: true
/jstransformer@1.0.0:
resolution: {integrity: sha1-7Yvwkh4vPx7U1cGkT2hwntJHIsM=}
dependencies:
is-promise: 2.2.2
promise: 7.3.1
dev: true
/kleur@3.0.3:
resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==}
engines: {node: '>=6'}
......@@ -9086,7 +9165,6 @@ packages:
/object-assign@4.1.1:
resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==}
engines: {node: '>=0.10.0'}
dev: false
/object-hash@3.0.0:
resolution: {integrity: sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==}
......@@ -9575,6 +9653,12 @@ packages:
engines: {node: '>= 0.6.0'}
dev: false
/promise@7.3.1:
resolution: {integrity: sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==}
dependencies:
asap: 2.0.6
dev: true
/prompts@2.4.2:
resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==}
engines: {node: '>= 6'}
......@@ -9620,6 +9704,97 @@ packages:
safe-buffer: 5.2.1
dev: true
/pug-attrs@3.0.0:
resolution: {integrity: sha512-azINV9dUtzPMFQktvTXciNAfAuVh/L/JCl0vtPCwvOA21uZrC08K/UnmrL+SXGEVc1FwzjW62+xw5S/uaLj6cA==}
dependencies:
constantinople: 4.0.1
js-stringify: 1.0.2
pug-runtime: 3.0.1
dev: true
/pug-code-gen@3.0.2:
resolution: {integrity: sha512-nJMhW16MbiGRiyR4miDTQMRWDgKplnHyeLvioEJYbk1RsPI3FuA3saEP8uwnTb2nTJEKBU90NFVWJBk4OU5qyg==}
dependencies:
constantinople: 4.0.1
doctypes: 1.1.0
js-stringify: 1.0.2
pug-attrs: 3.0.0
pug-error: 2.0.0
pug-runtime: 3.0.1
void-elements: 3.1.0
with: 7.0.2
dev: true
/pug-error@2.0.0:
resolution: {integrity: sha512-sjiUsi9M4RAGHktC1drQfCr5C5eriu24Lfbt4s+7SykztEOwVZtbFk1RRq0tzLxcMxMYTBR+zMQaG07J/btayQ==}
dev: true
/pug-filters@4.0.0:
resolution: {integrity: sha512-yeNFtq5Yxmfz0f9z2rMXGw/8/4i1cCFecw/Q7+D0V2DdtII5UvqE12VaZ2AY7ri6o5RNXiweGH79OCq+2RQU4A==}
dependencies:
constantinople: 4.0.1
jstransformer: 1.0.0
pug-error: 2.0.0
pug-walk: 2.0.0
resolve: 1.22.1
dev: true
/pug-lexer@5.0.1:
resolution: {integrity: sha512-0I6C62+keXlZPZkOJeVam9aBLVP2EnbeDw3An+k0/QlqdwH6rv8284nko14Na7c0TtqtogfWXcRoFE4O4Ff20w==}
dependencies:
character-parser: 2.2.0
is-expression: 4.0.0
pug-error: 2.0.0
dev: true
/pug-linker@4.0.0:
resolution: {integrity: sha512-gjD1yzp0yxbQqnzBAdlhbgoJL5qIFJw78juN1NpTLt/mfPJ5VgC4BvkoD3G23qKzJtIIXBbcCt6FioLSFLOHdw==}
dependencies:
pug-error: 2.0.0
pug-walk: 2.0.0
dev: true
/pug-load@3.0.0:
resolution: {integrity: sha512-OCjTEnhLWZBvS4zni/WUMjH2YSUosnsmjGBB1An7CsKQarYSWQ0GCVyd4eQPMFJqZ8w9xgs01QdiZXKVjk92EQ==}
dependencies:
object-assign: 4.1.1
pug-walk: 2.0.0
dev: true
/pug-parser@6.0.0:
resolution: {integrity: sha512-ukiYM/9cH6Cml+AOl5kETtM9NR3WulyVP2y4HOU45DyMim1IeP/OOiyEWRr6qk5I5klpsBnbuHpwKmTx6WURnw==}
dependencies:
pug-error: 2.0.0
token-stream: 1.0.0
dev: true
/pug-runtime@3.0.1:
resolution: {integrity: sha512-L50zbvrQ35TkpHwv0G6aLSuueDRwc/97XdY8kL3tOT0FmhgG7UypU3VztfV/LATAvmUfYi4wNxSajhSAeNN+Kg==}
dev: true
/pug-strip-comments@2.0.0:
resolution: {integrity: sha512-zo8DsDpH7eTkPHCXFeAk1xZXJbyoTfdPlNR0bK7rpOMuhBYb0f5qUVCO1xlsitYd3w5FQTK7zpNVKb3rZoUrrQ==}
dependencies:
pug-error: 2.0.0
dev: true
/pug-walk@2.0.0:
resolution: {integrity: sha512-yYELe9Q5q9IQhuvqsZNwA5hfPkMJ8u92bQLIMcsMxf/VADjNtEYptU+inlufAFYcWdHlwNfZOEnOOQrZrcyJCQ==}
dev: true
/pug@3.0.2:
resolution: {integrity: sha512-bp0I/hiK1D1vChHh6EfDxtndHji55XP/ZJKwsRqrz6lRia6ZC2OZbdAymlxdVFwd1L70ebrVJw4/eZ79skrIaw==}
dependencies:
pug-code-gen: 3.0.2
pug-filters: 4.0.0
pug-lexer: 5.0.1
pug-linker: 4.0.0
pug-load: 3.0.0
pug-parser: 6.0.0
pug-runtime: 3.0.1
pug-strip-comments: 2.0.0
dev: true
/pump@3.0.0:
resolution: {integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==}
dependencies:
......@@ -10516,6 +10691,10 @@ packages:
engines: {node: '>=0.6'}
dev: true
/token-stream@1.0.0:
resolution: {integrity: sha1-zCAOqyYT9BZtJ/+a/HylbUnfbrQ=}
dev: true
/tough-cookie@2.5.0:
resolution: {integrity: sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==}
engines: {node: '>=0.8'}
......@@ -10920,6 +11099,11 @@ packages:
resolution: {integrity: sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow==}
dev: true
/void-elements@3.1.0:
resolution: {integrity: sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w==}
engines: {node: '>=0.10.0'}
dev: true
/vue-i18n@9.1.9(vue@3.3.11):
resolution: {integrity: sha512-JeRdNVxS2OGp1E+pye5XB6+M6BBkHwAv9C80Q7+kzoMdUDGRna06tjC0vCB/jDX9aWrl5swxOMFcyAr7or8XTA==}
engines: {node: '>= 10'}
......@@ -11036,6 +11220,16 @@ packages:
dependencies:
isexe: 2.0.0
/with@7.0.2:
resolution: {integrity: sha512-RNGKj82nUPg3g5ygxkQl0R937xLyho1J24ItRCBTr/m1YnZkzJy1hUiHUJrc/VlsDQzsCnInEGSg3bci0Lmd4w==}
engines: {node: '>= 10.0.0'}
dependencies:
'@babel/parser': 7.23.6
'@babel/types': 7.21.5
assert-never: 1.2.1
babel-walk: 3.0.0-canary-5
dev: true
/word-wrap@1.2.3:
resolution: {integrity: sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==}
engines: {node: '>=0.10.0'}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册