Skip to content

Commit c57fb4e

Browse files
committed
remove export check
1 parent 1314197 commit c57fb4e

File tree

3 files changed

+150
-150
lines changed

3 files changed

+150
-150
lines changed

crates/emmylua_code_analysis/src/diagnostic/checker/check_field.rs

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use std::collections::HashSet;
22

33
use emmylua_parser::{
4-
LuaAst, LuaAstNode, LuaCallExpr, LuaElseIfClauseStat, LuaForRangeStat, LuaForStat, LuaIfStat,
5-
LuaIndexExpr, LuaIndexKey, LuaRepeatStat, LuaSyntaxKind, LuaTokenKind, LuaVarExpr,
6-
LuaWhileStat,
4+
LuaAst, LuaAstNode, LuaElseIfClauseStat, LuaForRangeStat, LuaForStat, LuaIfStat, LuaIndexExpr,
5+
LuaIndexKey, LuaRepeatStat, LuaSyntaxKind, LuaTokenKind, LuaVarExpr, LuaWhileStat,
76
};
87

98
use crate::{
109
DiagnosticCode, InferFailReason, LuaMemberKey, LuaSemanticDeclId, LuaType, ModuleInfo,
11-
SemanticModel, enum_variable_is_param, parse_require_module_info,
10+
SemanticModel, enum_variable_is_param,
1211
};
1312

1413
use super::{Checker, DiagnosticContext, humanize_lint_type};
@@ -64,18 +63,19 @@ fn check_index_expr(
6463
let prefix_typ = semantic_model
6564
.infer_expr(index_expr.get_prefix_expr()?)
6665
.unwrap_or(LuaType::Unknown);
67-
let mut module_info = None;
66+
// let mut module_info = None;
6867

6968
if is_invalid_prefix_type(&prefix_typ) {
70-
if matches!(prefix_typ, LuaType::TableConst(_)) {
71-
// 如果导入了被 @export 标记的表常量, 那么不应该跳过检查
72-
module_info = check_require_table_const_with_export(semantic_model, index_expr);
73-
if module_info.is_none() {
74-
return Some(());
75-
}
76-
} else {
77-
return Some(());
78-
}
69+
// if matches!(prefix_typ, LuaType::TableConst(_)) {
70+
// // 如果导入了被 @export 标记的表常量, 那么不应该跳过检查
71+
// module_info = check_require_table_const_with_export(semantic_model, index_expr);
72+
// if module_info.is_none() {
73+
// return Some(());
74+
// }
75+
// } else {
76+
77+
// }
78+
return Some(());
7979
}
8080

8181
let index_key = index_expr.get_index_key()?;
@@ -86,7 +86,7 @@ fn check_index_expr(
8686
index_expr,
8787
&index_key,
8888
code,
89-
module_info,
89+
None,
9090
)
9191
.is_some()
9292
{
@@ -479,57 +479,57 @@ fn check_enum_is_param(
479479
)
480480
}
481481

482-
/// 检查导入的表常量
483-
fn check_require_table_const_with_export<'a>(
484-
semantic_model: &'a SemanticModel,
485-
index_expr: &LuaIndexExpr,
486-
) -> Option<&'a ModuleInfo> {
487-
// 获取前缀表达式的语义信息
488-
let prefix_expr = index_expr.get_prefix_expr()?;
489-
if let Some(call_expr) = LuaCallExpr::cast(prefix_expr.syntax().clone()) {
490-
let module_info = parse_require_expr_module_info(semantic_model, &call_expr)?;
491-
if module_info.is_export(semantic_model.get_db()) {
492-
return Some(module_info);
493-
}
494-
}
495-
496-
let semantic_info = semantic_model.get_semantic_info(prefix_expr.syntax().clone().into())?;
497-
498-
// 检查是否是声明引用
499-
let decl_id = match semantic_info.semantic_decl? {
500-
LuaSemanticDeclId::LuaDecl(decl_id) => decl_id,
501-
_ => return None,
502-
};
503-
504-
// 获取声明
505-
let decl = semantic_model
506-
.get_db()
507-
.get_decl_index()
508-
.get_decl(&decl_id)?;
509-
510-
let module_info = parse_require_module_info(semantic_model, decl)?;
511-
if module_info.is_export(semantic_model.get_db()) {
512-
return Some(module_info);
513-
}
514-
None
515-
}
516-
517-
pub fn parse_require_expr_module_info<'a>(
518-
semantic_model: &'a SemanticModel,
519-
call_expr: &LuaCallExpr,
520-
) -> Option<&'a ModuleInfo> {
521-
let arg_list = call_expr.get_args_list()?;
522-
let first_arg = arg_list.get_args().next()?;
523-
let require_path_type = semantic_model.infer_expr(first_arg.clone()).ok()?;
524-
let module_path: String = match &require_path_type {
525-
LuaType::StringConst(module_path) => module_path.as_ref().to_string(),
526-
_ => {
527-
return None;
528-
}
529-
};
530-
531-
semantic_model
532-
.get_db()
533-
.get_module_index()
534-
.find_module(&module_path)
535-
}
482+
// /// 检查导入的表常量
483+
// fn check_require_table_const_with_export<'a>(
484+
// semantic_model: &'a SemanticModel,
485+
// index_expr: &LuaIndexExpr,
486+
// ) -> Option<&'a ModuleInfo> {
487+
// // 获取前缀表达式的语义信息
488+
// let prefix_expr = index_expr.get_prefix_expr()?;
489+
// if let Some(call_expr) = LuaCallExpr::cast(prefix_expr.syntax().clone()) {
490+
// let module_info = parse_require_expr_module_info(semantic_model, &call_expr)?;
491+
// if module_info.is_export(semantic_model.get_db()) {
492+
// return Some(module_info);
493+
// }
494+
// }
495+
496+
// let semantic_info = semantic_model.get_semantic_info(prefix_expr.syntax().clone().into())?;
497+
498+
// // 检查是否是声明引用
499+
// let decl_id = match semantic_info.semantic_decl? {
500+
// LuaSemanticDeclId::LuaDecl(decl_id) => decl_id,
501+
// _ => return None,
502+
// };
503+
504+
// // 获取声明
505+
// let decl = semantic_model
506+
// .get_db()
507+
// .get_decl_index()
508+
// .get_decl(&decl_id)?;
509+
510+
// let module_info = parse_require_module_info(semantic_model, decl)?;
511+
// if module_info.is_export(semantic_model.get_db()) {
512+
// return Some(module_info);
513+
// }
514+
// None
515+
// }
516+
517+
// pub fn parse_require_expr_module_info<'a>(
518+
// semantic_model: &'a SemanticModel,
519+
// call_expr: &LuaCallExpr,
520+
// ) -> Option<&'a ModuleInfo> {
521+
// let arg_list = call_expr.get_args_list()?;
522+
// let first_arg = arg_list.get_args().next()?;
523+
// let require_path_type = semantic_model.infer_expr(first_arg.clone()).ok()?;
524+
// let module_path: String = match &require_path_type {
525+
// LuaType::StringConst(module_path) => module_path.as_ref().to_string(),
526+
// _ => {
527+
// return None;
528+
// }
529+
// };
530+
531+
// semantic_model
532+
// .get_db()
533+
// .get_module_index()
534+
// .find_module(&module_path)
535+
// }

crates/emmylua_code_analysis/src/diagnostic/test/inject_field_test.rs

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -151,63 +151,63 @@ mod test {
151151
// ));
152152
// }
153153

154-
#[test]
155-
fn test_export() {
156-
let mut ws = VirtualWorkspace::new();
157-
ws.def_file(
158-
"a.lua",
159-
r#"
160-
---@export
161-
local export = {}
154+
// #[test]
155+
// fn test_export() {
156+
// let mut ws = VirtualWorkspace::new();
157+
// ws.def_file(
158+
// "a.lua",
159+
// r#"
160+
// ---@export
161+
// local export = {}
162162

163-
export.a = 1
163+
// export.a = 1
164164

165-
return export
166-
"#,
167-
);
168-
assert!(!ws.check_code_for(
169-
DiagnosticCode::InjectField,
170-
r#"
171-
local a = require("a")
172-
a.newField = 1
173-
"#,
174-
));
175-
assert!(ws.check_code_for(
176-
DiagnosticCode::InjectField,
177-
r#"
178-
local a = require("a")
179-
a.a = 2
180-
"#,
181-
));
182-
}
165+
// return export
166+
// "#,
167+
// );
168+
// assert!(!ws.check_code_for(
169+
// DiagnosticCode::InjectField,
170+
// r#"
171+
// local a = require("a")
172+
// a.newField = 1
173+
// "#,
174+
// ));
175+
// assert!(ws.check_code_for(
176+
// DiagnosticCode::InjectField,
177+
// r#"
178+
// local a = require("a")
179+
// a.a = 2
180+
// "#,
181+
// ));
182+
// }
183183

184-
#[test]
185-
fn test_export_2() {
186-
let mut ws = VirtualWorkspace::new();
187-
ws.def_file(
188-
"a.lua",
189-
r#"
190-
---@export
191-
return {
192-
a = 1
193-
}
194-
"#,
195-
);
196-
assert!(!ws.check_code_for(
197-
DiagnosticCode::InjectField,
198-
r#"
199-
local a = require("a")
200-
a.newField = 1
201-
"#,
202-
));
203-
assert!(ws.check_code_for(
204-
DiagnosticCode::InjectField,
205-
r#"
206-
local a = require("a")
207-
a.a = 2
208-
"#,
209-
));
210-
}
184+
// #[test]
185+
// fn test_export_2() {
186+
// let mut ws = VirtualWorkspace::new();
187+
// ws.def_file(
188+
// "a.lua",
189+
// r#"
190+
// ---@export
191+
// return {
192+
// a = 1
193+
// }
194+
// "#,
195+
// );
196+
// assert!(!ws.check_code_for(
197+
// DiagnosticCode::InjectField,
198+
// r#"
199+
// local a = require("a")
200+
// a.newField = 1
201+
// "#,
202+
// ));
203+
// assert!(ws.check_code_for(
204+
// DiagnosticCode::InjectField,
205+
// r#"
206+
// local a = require("a")
207+
// a.a = 2
208+
// "#,
209+
// ));
210+
// }
211211

212212
#[test]
213213
fn test_issue_660() {

crates/emmylua_code_analysis/src/diagnostic/test/undefined_field_test.rs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -736,31 +736,31 @@ mod test {
736736
));
737737
}
738738

739-
#[test]
740-
fn test_export() {
741-
let mut ws = VirtualWorkspace::new();
742-
ws.def_file(
743-
"a.lua",
744-
r#"
745-
---@export
746-
local export = {}
747-
748-
return export
749-
"#,
750-
);
751-
assert!(!ws.check_code_for(
752-
DiagnosticCode::UndefinedField,
753-
r#"
754-
local a = require("a")
755-
a.func()
756-
"#,
757-
));
758-
759-
assert!(!ws.check_code_for(
760-
DiagnosticCode::UndefinedField,
761-
r#"
762-
local a = require("a").ABC
763-
"#,
764-
));
765-
}
739+
// #[test]
740+
// fn test_export() {
741+
// let mut ws = VirtualWorkspace::new();
742+
// ws.def_file(
743+
// "a.lua",
744+
// r#"
745+
// ---@export
746+
// local export = {}
747+
748+
// return export
749+
// "#,
750+
// );
751+
// assert!(!ws.check_code_for(
752+
// DiagnosticCode::UndefinedField,
753+
// r#"
754+
// local a = require("a")
755+
// a.func()
756+
// "#,
757+
// ));
758+
759+
// assert!(!ws.check_code_for(
760+
// DiagnosticCode::UndefinedField,
761+
// r#"
762+
// local a = require("a").ABC
763+
// "#,
764+
// ));
765+
// }
766766
}

0 commit comments

Comments
 (0)