Skip to content

Commit 0731e0c

Browse files
wip(core): enhance compiledCache key management
1 parent 9ff80e3 commit 0731e0c

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/createVue2SFCModule.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
8989

9090
const component = {};
9191

92-
const { delimiters, moduleCache, compiledCache, getResource, addStyle, log, additionalBabelPlugins = [], customBlockHandler } = options;
92+
const { delimiters, moduleCache, compiledCache, getResource, addStyle, log, additionalBabelPlugins = {}, customBlockHandler } = options;
9393

9494
const descriptor = sfc_parse({
9595
source,
@@ -154,9 +154,9 @@ export async function createSFCModule(source : string, filename : AbstractPath,
154154

155155
const src = descriptor.script.src ? (await getResource({ refPath: filename, relPath: descriptor.script.src }, options).getContent()).content.toString() : descriptor.script.content;
156156

157-
const [ depsList, transformedScriptSource ] = await withCache(compiledCache, [ componentHash, src ], async ({ preventCache }) => {
157+
const babelParserPlugins : babel_ParserPlugin[] = [];
158158

159-
const babelParserPlugins : babel_ParserPlugin[] = [];
159+
const [ depsList, transformedScriptSource ] = await withCache(compiledCache, [ componentHash, src, JSON.stringify(babelParserPlugins), Object.keys(additionalBabelPlugins) ], async ({ preventCache }) => {
160160

161161
let ast: t.File
162162
try {
@@ -188,7 +188,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
188188
pluginProposalOptionalChaining,
189189
pluginProposalNullishCoalescingOperator,
190190
babelSugarInjectH,
191-
...additionalBabelPlugins,
191+
...Object.values(additionalBabelPlugins),
192192
],
193193
babelrc: false,
194194
configFile: false,

src/createVue3SFCModule.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
9090

9191
const component = {};
9292

93-
const { delimiters, moduleCache, compiledCache, getResource, addStyle, log, additionalBabelPlugins = [], customBlockHandler } = options;
93+
const { delimiters, moduleCache, compiledCache, getResource, addStyle, log, additionalBabelPlugins = {}, customBlockHandler } = options;
9494

9595
// vue-loader next: https://github.com/vuejs/vue-loader/blob/next/src/index.ts#L91
9696
const { descriptor, errors } = sfc_parse(source, {
@@ -140,16 +140,15 @@ export async function createSFCModule(source : string, filename : AbstractPath,
140140

141141
// TBD: handle <script setup src="...
142142

143+
const babelParserPlugins : babel_ParserPlugin[] = [];
143144

144-
const [ depsList, transformedScriptSource ] = await withCache(compiledCache, [ componentHash, descriptor.script?.content, descriptor.scriptSetup?.content ], async ({ preventCache }) => {
145-
146-
const babelParserPlugins : babel_ParserPlugin[] = [];
145+
const [ depsList, transformedScriptSource ] = await withCache(compiledCache, [ componentHash, descriptor.script?.content, descriptor.scriptSetup?.content, JSON.stringify(babelParserPlugins), Object.keys(additionalBabelPlugins) ], async ({ preventCache }) => {
147146

148147
// src: https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileScript.ts#L43
149148
const scriptBlock = sfc_compileScript(descriptor, {
150149
isProd,
151150
id: scopeId,
152-
babelParserPlugins,
151+
babelParserPlugins, // [...babelParserDefaultPlugins, 'jsx'] + babelParserPlugins // babelParserDefaultPlugins = [ 'bigInt', 'optionalChaining', 'nullishCoalescingOperator' ]
153152
// doc: https://github.com/vuejs/rfcs/blob/script-setup-2/active-rfcs/0000-script-setup.md#inline-template-mode
154153
// vue-loader next : https://github.com/vuejs/vue-loader/blob/12aaf2ea77add8654c50c8751bad135f1881e53f/src/resolveScript.ts#L59
155154
inlineTemplate: false,
@@ -174,7 +173,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
174173
// if: https://github.com/babel/babel/blob/main/packages/babel-parser/typings/babel-parser.d.ts#L24
175174
plugins: [
176175
// see https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileScript.ts#L63
177-
...vue_babelParserDefaultPlugins,
176+
...vue_babelParserDefaultPlugins, // [ 'bigInt', 'optionalChaining', 'nullishCoalescingOperator' ]
178177
'jsx',
179178
...babelParserPlugins
180179
],
@@ -207,7 +206,7 @@ export async function createSFCModule(source : string, filename : AbstractPath,
207206
jsx,
208207
pluginProposalOptionalChaining,
209208
pluginProposalNullishCoalescingOperator,
210-
...additionalBabelPlugins,
209+
...Object.values(additionalBabelPlugins),
211210
],
212211
babelrc: false,
213212
configFile: false,

src/tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ export function parseDeps(fileAst : t.File) : string[] {
205205
*/
206206
export async function transformJSCode(source : string, moduleSourceType : boolean, filename : AbstractPath, options : Options) : Promise<[string[], string]> {
207207

208-
const { additionalBabelPlugins = [], log } = options;
208+
const { additionalBabelPlugins = {}, log } = options;
209209

210210
let ast: t.File;
211211
try {
@@ -228,7 +228,7 @@ export async function transformJSCode(source : string, moduleSourceType : boolea
228228
sourceMaps: genSourcemap, // doc: https://babeljs.io/docs/en/options#sourcemaps
229229
plugins: [ // https://babeljs.io/docs/en/options#plugins
230230
babelPluginTransformModulesCommonjs, // https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#options
231-
...additionalBabelPlugins
231+
...Object.values(additionalBabelPlugins),
232232
],
233233
babelrc: false,
234234
configFile: false,

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export type Options = {
242242
* ...
243243
* ```
244244
*/
245-
additionalBabelPlugins?: any[],
245+
additionalBabelPlugins?: Record<string, any>,
246246

247247

248248
/**

0 commit comments

Comments
 (0)