@@ -4,7 +4,6 @@ import { codeFeatures } from '../codeFeatures';
44import type { InlayHintInfo } from '../inlayHints' ;
55import { endOfLine , newLine } from '../utils' ;
66import { endBoundary , startBoundary } from '../utils/boundary' ;
7- import type { TemplateCodegenOptions } from './index' ;
87
98export type TemplateCodegenContext = ReturnType < typeof createTemplateCodegenContext > ;
109
@@ -108,14 +107,14 @@ const commentDirectiveRegex = /^<!--\s*@vue-(?<name>[-\w]+)\b(?<content>[\s\S]*)
108107 * and additionally how we use that to determine whether to propagate diagnostics back upward.
109108 */
110109export function createTemplateCodegenContext (
111- options : Pick < TemplateCodegenOptions , 'scriptSetupBindingNames' > ,
110+ scriptBindings : Set < string > ,
112111) {
113112 let variableId = 0 ;
114113
115- const scopes = [ new Set < string > ( ) ] ;
114+ const scopes : Set < string > [ ] = [ ] ;
116115 const hoistVars = new Map < string , string > ( ) ;
117116 const dollarVars = new Set < string > ( ) ;
118- const accessExternalVariables = new Map < string , Set < number > > ( ) ;
117+ const accessExternalVariables = new Map < string , Map < string , Set < number > > > ( ) ;
119118 const slots : {
120119 name : string ;
121120 offset ?: number ;
@@ -176,10 +175,14 @@ export function createTemplateCodegenContext(
176175 }
177176 refs . push ( { typeExp, offset } ) ;
178177 } ,
179- accessExternalVariable ( name : string , offset ?: number ) {
180- let arr = accessExternalVariables . get ( name ) ;
178+ accessExternalVariable ( source : string , name : string , offset ?: number ) {
179+ let map = accessExternalVariables . get ( name ) ;
180+ if ( ! map ) {
181+ accessExternalVariables . set ( name , map = new Map ( ) ) ;
182+ }
183+ let arr = map . get ( source ) ;
181184 if ( ! arr ) {
182- accessExternalVariables . set ( name , arr = new Set ( ) ) ;
185+ map . set ( source , arr = new Set ( ) ) ;
183186 }
184187 if ( offset !== undefined ) {
185188 arr . add ( offset ) ;
@@ -301,31 +304,33 @@ export function createTemplateCodegenContext(
301304 }
302305 yield `// @ts-ignore${ newLine } ` ; // #2304
303306 yield `[` ;
304- for ( const [ varName , offsets ] of all ) {
305- for ( const offset of offsets ) {
306- if ( options . scriptSetupBindingNames . has ( varName ) ) {
307- // #3409
308- yield [
309- varName ,
310- 'template' ,
311- offset ,
312- {
313- ...codeFeatures . additionalCompletion ,
314- ...codeFeatures . semanticWithoutHighlight ,
315- } ,
316- ] ;
317- }
318- else {
319- yield [
320- varName ,
321- 'template' ,
322- offset ,
323- codeFeatures . additionalCompletion ,
324- ] ;
307+ for ( const [ varName , map ] of all ) {
308+ for ( const [ source , offsets ] of map ) {
309+ for ( const offset of offsets ) {
310+ if ( scriptBindings . has ( varName ) ) {
311+ // #3409
312+ yield [
313+ varName ,
314+ source ,
315+ offset ,
316+ {
317+ ...codeFeatures . additionalCompletion ,
318+ ...codeFeatures . semanticWithoutHighlight ,
319+ } ,
320+ ] ;
321+ }
322+ else {
323+ yield [
324+ varName ,
325+ source ,
326+ offset ,
327+ codeFeatures . additionalCompletion ,
328+ ] ;
329+ }
330+ yield `,` ;
325331 }
326- yield `,` ;
332+ offsets . clear ( ) ;
327333 }
328- offsets . clear ( ) ;
329334 }
330335 yield `]${ endOfLine } ` ;
331336 }
0 commit comments