File tree Expand file tree Collapse file tree 2 files changed +21
-3
lines changed
packages/theme-check-common/src/checks Expand file tree Collapse file tree 2 files changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import {
1616import { LiquidCheckDefinition , Severity , SourceCodeType , ThemeDocset } from '../../types' ;
1717import { isError , last } from '../../utils' ;
1818import { hasLiquidDoc } from '../../liquid-doc/liquidDoc' ;
19- import { isWithinRawTagThatDoesNotParseItsContents } from '../utils' ;
19+ import { isWithinRawTagThatDoesNotParseItsContents , findInlineSnippetAncestor } from '../utils' ;
2020
2121type Scope = { start ?: number ; end ?: number } ;
2222
@@ -66,9 +66,16 @@ export const UndefinedObject: LiquidCheckDefinition = {
6666 }
6767
6868 return {
69- async LiquidDocParamNode ( node : LiquidDocParamNode ) {
69+ async LiquidDocParamNode ( node : LiquidDocParamNode , ancestors : LiquidHtmlNode [ ] ) {
7070 const paramName = node . paramName ?. value ;
71- if ( paramName ) {
71+ if ( ! paramName ) return ;
72+ const snippetAncestor = findInlineSnippetAncestor ( ancestors ) ;
73+ if ( snippetAncestor ) {
74+ indexVariableScope ( paramName , {
75+ start : snippetAncestor . blockStartPosition . end ,
76+ end : snippetAncestor . blockEndPosition ?. start ,
77+ } ) ;
78+ } else {
7279 fileScopedVariables . add ( paramName ) ;
7380 }
7481 } ,
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
1313 LiquidTagTablerow ,
1414 LiquidTag ,
1515 LoopNamedTags ,
16+ NamedTags ,
1617} from '@shopify/liquid-html-parser' ;
1718import { LiquidHtmlNodeOfType as NodeOfType } from '../types' ;
1819
@@ -104,6 +105,16 @@ export function isLoopLiquidTag(tag: LiquidTag): tag is LiquidTagFor | LiquidTag
104105 return LoopNamedTags . includes ( tag . name as any ) ;
105106}
106107
108+ export function findInlineSnippetAncestor ( ancestors : LiquidHtmlNode [ ] ) {
109+ for ( let i = ancestors . length - 1 ; i >= 0 ; i -- ) {
110+ const ancestor = ancestors [ i ] ;
111+ if ( ancestor . type === NodeTypes . LiquidTag && ancestor . name === NamedTags . snippet ) {
112+ return ancestor ;
113+ }
114+ }
115+ return null ;
116+ }
117+
107118const RawTagsThatDoNotParseTheirContents = [ 'raw' , 'stylesheet' , 'javascript' , 'schema' ] ;
108119
109120function isRawTagThatDoesNotParseItsContent ( node : LiquidHtmlNode ) {
You can’t perform that action at this time.
0 commit comments