Skip to content

Commit 6a32feb

Browse files
committed
fix(core), SFC style CSS variable injection (new edition) support, see vuejs/rfcs#231
sfc_compileScript().scriptAst is not usable any more, see https://github.com/vuejs/vue-next/blob/3532b2b0213268a285cacce9b38f806e6af29a61/packages/compiler-sfc/src/compileScript.ts#L128
1 parent 4681ee7 commit 6a32feb

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

src/index.ts

+14-25
Original file line numberDiff line numberDiff line change
@@ -510,33 +510,22 @@ async function createSFCModule(source : string, filename : string, options : Opt
510510
babelParserPlugins,
511511
});
512512

513-
if ( script.scriptAst === undefined ) { // if error
514-
515-
try {
516-
517-
// get the error
518-
const ast = babel_parse(descriptor.script.content, {
519-
// doc: https://babeljs.io/docs/en/babel-parser#options
520-
plugins: [...vue_babelParserDefaultPlugins, 'jsx', ...babelParserPlugins], // see https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileScript.ts#L63
521-
sourceType: 'module',
522-
sourceFilename: filename,
523-
});
524-
525-
} catch (ex) {
526-
527-
preventCache();
528-
log?.('error', 'SFC script', ex);
529-
}
530-
}
531-
532-
const program = t.program(script.scriptAst, [], 'module') // doc: https://babeljs.io/docs/en/babel-types#program
533-
program.loc = script.loc;
513+
const ast = babel_parse(script.content, {
514+
// doc: https://babeljs.io/docs/en/babel-parser#options
515+
plugins: [
516+
// see https://github.com/vuejs/vue-next/blob/15baaf14f025f6b1d46174c9713a2ec517741d0d/packages/compiler-sfc/src/compileScript.ts#L63
517+
...vue_babelParserDefaultPlugins,
518+
'jsx',
519+
...babelParserPlugins
520+
],
521+
sourceType: 'module',
522+
sourceFilename: filename,
523+
});
534524

535-
const file = t.file(program); // doc: https://babeljs.io/docs/en/babel-types#file
536-
renameDynamicImport(file);
537-
const depsList = parseDeps(file);
525+
renameDynamicImport(ast);
526+
const depsList = parseDeps(ast);
538527

539-
const transformedScript = await babel_transformFromAstAsync(program, script.content, {
528+
const transformedScript = await babel_transformFromAstAsync(ast, script.content, {
540529
sourceMaps: genSourcemap, // https://babeljs.io/docs/en/options#sourcemaps
541530
plugins: [ // https://babeljs.io/docs/en/options#plugins
542531
babelPluginTransformModulesCommonjs, // https://babeljs.io/docs/en/babel-plugin-transform-modules-commonjs#options

0 commit comments

Comments
 (0)