@@ -29,6 +29,8 @@ export function checkPagesJson(jsonStr: string, inputDir: string) {
2929 }
3030 const errors : ParseError [ ] = [ ]
3131 const root = parseTree ( jsonStr , errors )
32+ let allPages : string [ ] = [ ] // 收集全部页面,包含分包页面
33+ let tabBarPages : string [ ] = [ ] // 收集 tabBar 页面
3234 if ( ! root ) {
3335 if ( errors . length ) {
3436 for ( const error of errors ) {
@@ -88,6 +90,41 @@ export function checkPagesJson(jsonStr: string, inputDir: string) {
8890 }
8991 } )
9092
93+ allPages . push ( ...pagePathNodes . map ( ( node ) => node . value as string ) )
94+
95+ const tabBarNode = root . children ?. find (
96+ ( child ) =>
97+ child . type === 'property' &&
98+ child . children ?. length === 2 &&
99+ child . children [ 0 ] . value === 'tabBar'
100+ )
101+ if ( tabBarNode ) {
102+ findRootNode ( tabBarNode . children ! [ 1 ] , [ 'list' ] ) . forEach ( ( node ) => {
103+ const pagePathNode =
104+ node . type === 'object' &&
105+ node . children ?. find (
106+ ( child ) =>
107+ child . type === 'property' &&
108+ child . children ?. length === 2 &&
109+ child . children [ 0 ] . value === 'pagePath'
110+ )
111+ if ( pagePathNode ) {
112+ const pagePathValueNode = pagePathNode . children ! [ 1 ]
113+ const pagePath = pagePathValueNode . value as string
114+ tabBarPages . push ( pagePath )
115+ if (
116+ ! allPages . includes ( pagePath ) &&
117+ ! allPages . includes ( pagePath . substring ( 1 ) )
118+ ) {
119+ throwCompilerError (
120+ jsonStr ,
121+ pagePathValueNode ,
122+ M [ 'pages.json.tabbar.page.notfound' ] . replace ( '{pagePath}' , pagePath )
123+ )
124+ }
125+ }
126+ } )
127+ }
91128 for ( const node of pagePathNodes ) {
92129 const pagePath : string = node . value ?? ''
93130 if ( ! pageExistsWithCaseSync ( path . join ( inputDir , pagePath ) ) ) {
0 commit comments