File tree Expand file tree Collapse file tree 3 files changed +45
-22
lines changed
packages/language-core/lib/codegen/template Expand file tree Collapse file tree 3 files changed +45
-22
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,8 @@ export function createTemplateCodegenContext(options: Pick<TemplateCodegenOption
125125} [ ] = [ ] ;
126126const emptyClassOffsets : number [ ] = [ ] ;
127127const inlayHints : InlayHintInfo [ ] = [ ] ;
128+ const bindingAttrLocs : CompilerDOM . SourceLocation [ ] = [ ] ;
129+ const inheritedAttrVars = new Set < string > ( ) ;
128130const templateRefs = new Map < string , [ varName : string , offset : number ] > ( ) ;
129131
130132return {
@@ -140,7 +142,8 @@ export function createTemplateCodegenContext(options: Pick<TemplateCodegenOption
140142emptyClassOffsets,
141143inlayHints,
142144hasSlot : false ,
143- inheritedAttrVars : new Set ( ) ,
145+ bindingAttrLocs,
146+ inheritedAttrVars,
144147templateRefs,
145148singleRootElType : undefined as string | undefined ,
146149singleRootNode : undefined as CompilerDOM . ElementNode | undefined ,
Original file line number Diff line number Diff line change @@ -240,28 +240,35 @@ export function* generateElementProps(
240240&& ! prop . arg
241241&& prop . exp ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION
242242) {
243- const codes = wrapWith (
244- prop . exp . loc . start . offset ,
245- prop . exp . loc . end . offset ,
246- ctx . codeFeatures . verification ,
247- `...` ,
248- ...generatePropExp (
249- options ,
250- ctx ,
251- prop ,
252- prop . exp ,
253- ctx . codeFeatures . all ,
254- false ,
255- enableCodeFeatures
256- )
257- ) ;
258- if ( enableCodeFeatures ) {
259- yield * codes ;
243+ if ( prop . exp . loc . source === '$attrs' ) {
244+ if ( enableCodeFeatures ) {
245+ ctx . bindingAttrLocs . push ( prop . exp . loc ) ;
246+ }
260247}
261248else {
262- yield toString ( [ ...codes ] ) ;
249+ const codes = wrapWith (
250+ prop . exp . loc . start . offset ,
251+ prop . exp . loc . end . offset ,
252+ ctx . codeFeatures . verification ,
253+ `...` ,
254+ ...generatePropExp (
255+ options ,
256+ ctx ,
257+ prop ,
258+ prop . exp ,
259+ ctx . codeFeatures . all ,
260+ false ,
261+ enableCodeFeatures
262+ )
263+ ) ;
264+ if ( enableCodeFeatures ) {
265+ yield * codes ;
266+ }
267+ else {
268+ yield toString ( [ ...codes ] ) ;
269+ }
270+ yield `,${ newLine } ` ;
263271}
264- yield `,${ newLine } ` ;
265272}
266273}
267274}
Original file line number Diff line number Diff line change @@ -35,9 +35,8 @@ export function* generateTemplate(options: TemplateCodegenOptions): Generator<Co
3535if ( options . propsAssignName ) {
3636ctx . addLocalVariable ( options . propsAssignName ) ;
3737}
38- // TODO: circular reference
39- // ctx.addLocalVariable('$attrs');
4038ctx . addLocalVariable ( getSlotsPropertyName ( options . vueCompilerOptions . target ) ) ;
39+ ctx . addLocalVariable ( '$attrs' ) ;
4140ctx . addLocalVariable ( '$refs' ) ;
4241ctx . addLocalVariable ( '$el' ) ;
4342
@@ -100,6 +99,20 @@ function* generateInheritedAttrs(ctx: TemplateCodegenContext): Generator<Code> {
10099}
101100yield endOfLine ;
102101yield `var $attrs!: Partial<typeof __VLS_inheritedAttrs> & Record<string, unknown>${ endOfLine } ` ;
102+
103+ if ( ctx . bindingAttrLocs . length ) {
104+ yield `[` ;
105+ for ( const loc of ctx . bindingAttrLocs ) {
106+ yield [
107+ loc . source ,
108+ 'template' ,
109+ loc . start . offset ,
110+ ctx . codeFeatures . all
111+ ] ;
112+ yield `,` ;
113+ }
114+ yield `]${ endOfLine } ` ;
115+ }
103116}
104117
105118function * generateRefs ( ctx : TemplateCodegenContext ) : Generator < Code > {
You can’t perform that action at this time.
0 commit comments