Skip to content

Commit 44a9df8

Browse files
committed
test(linter): update testsuite for no-undef (#11706)
1 parent 20efcd4 commit 44a9df8

File tree

1 file changed

+100
-90
lines changed

1 file changed

+100
-90
lines changed

crates/oxc_linter/src/rules/eslint/no_undef.rs

Lines changed: 100 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -91,108 +91,118 @@ fn test() {
9191
use crate::tester::Tester;
9292

9393
let pass = vec![
94-
"var a = 1, b = 2; a;",
94+
("var a = 1, b = 2; a;", None, None),
9595
// "/*global b*/ function f() { b; }",
96-
// { code: "function f() { b; }", globals: { b: false } },
96+
("function f() { b; }", None, Some(serde_json::json!({"globals": { "b": false }}))),
9797
// "/*global b a:false*/ a; function f() { b; a; }",
98-
"function a(){} a();",
99-
"function f(b) { b; }",
100-
"var a; a = 1; a++;",
101-
"var a; function f() { a = 1; }",
98+
("function a(){} a();", None, None),
99+
("function f(b) { b; }", None, None),
100+
("var a; a = 1; a++;", None, None),
101+
("var a; function f() { a = 1; }", None, None),
102102
// "/*global b:true*/ b++;",
103103
// "/*eslint-env browser*/ window;",
104104
// "/*eslint-env node*/ require(\"a\");",
105-
"Object; isNaN();",
106-
"function evilEval(stuffToEval) { var ultimateAnswer; ultimateAnswer = 42; eval(stuffToEval); }",
107-
"typeof a",
108-
"typeof (a)",
109-
"var b = typeof a",
110-
"typeof a === 'undefined'",
111-
"if (typeof a === 'undefined') {}",
112-
"function foo() { var [a, b=4] = [1, 2]; return {a, b}; }",
113-
"var toString = 1;",
114-
"function myFunc(...foo) { return foo;}",
115-
"var React, App, a=1; React.render(<App attr={a} />);",
116-
"var console; [1,2,3].forEach(obj => {\n console.log(obj);\n});",
117-
"var Foo; class Bar extends Foo { constructor() { super(); }}",
118-
"import Warning from '../lib/warning'; var warn = new Warning('text');",
119-
"import * as Warning from '../lib/warning'; var warn = new Warning('text');",
120-
"var a; [a] = [0];",
121-
"var a; ({a} = {});",
122-
"var a; ({b: a} = {});",
123-
"var obj; [obj.a, obj.b] = [0, 1];",
124-
// "URLSearchParams;",
125-
// "Intl;",
126-
// "IntersectionObserver;",
127-
// "Credential;",
128-
// "requestIdleCallback;",
129-
// "customElements;",
130-
// "PromiseRejectionEvent;",
131-
"(foo, bar) => { foo ||= WeakRef; bar ??= FinalizationRegistry; }",
105+
("Object; isNaN();", None, None),
106+
(
107+
"function evilEval(stuffToEval) { var ultimateAnswer; ultimateAnswer = 42; eval(stuffToEval); }",
108+
None,
109+
None,
110+
),
111+
("typeof a", None, None),
112+
("typeof (a)", None, None),
113+
("var b = typeof a", None, None),
114+
("typeof a === 'undefined'", None, None),
115+
("if (typeof a === 'undefined') {}", None, None),
116+
("function foo() { var [a, b=4] = [1, 2]; return {a, b}; }", None, None),
117+
("var toString = 1;", None, None),
118+
("function myFunc(...foo) { return foo;}", None, None),
119+
("var React, App, a=1; React.render(<App attr={a} />);", None, None),
120+
("var console; [1,2,3].forEach(obj => {\n console.log(obj);\n});", None, None),
121+
("var Foo; class Bar extends Foo { constructor() { super(); }}", None, None),
122+
("import Warning from '../lib/warning'; var warn = new Warning('text');", None, None),
123+
("import * as Warning from '../lib/warning'; var warn = new Warning('text');", None, None),
124+
("var a; [a] = [0];", None, None),
125+
("var a; ({a} = {});", None, None),
126+
("var a; ({b: a} = {});", None, None),
127+
("var obj; [obj.a, obj.b] = [0, 1];", None, None),
128+
("URLSearchParams;", None, Some(serde_json::json!({"env": { "browser": true }}))),
129+
("Intl;", None, Some(serde_json::json!({"env": { "browser": true }}))),
130+
("IntersectionObserver;", None, Some(serde_json::json!({"env": { "browser": true }}))),
131+
("Credential;", None, Some(serde_json::json!({"env": { "browser": true }}))),
132+
("requestIdleCallback;", None, Some(serde_json::json!({"env": { "browser": true }}))),
133+
("customElements;", None, Some(serde_json::json!({"env": { "browser": true }}))),
134+
("PromiseRejectionEvent;", None, Some(serde_json::json!({"env": { "browser": true }}))),
135+
("(foo, bar) => { foo ||= WeakRef; bar ??= FinalizationRegistry; }", None, None),
136+
("class C extends C {}", None, None),
132137
// "/*global b:false*/ function f() { b = 1; }",
133-
// { code: "function f() { b = 1; }", globals: { b: false } },
138+
("function f() { b = 1; }", None, Some(serde_json::json!({"globals": { "b": false } }))),
134139
// "/*global b:false*/ function f() { b++; }",
135140
// "/*global b*/ b = 1;",
136141
// "/*global b:false*/ var b = 1;",
137-
"Array = 1;",
138-
"class A { constructor() { new.target; } }",
139-
// {
140-
// code: "var {bacon, ...others} = stuff; foo(others)",
141-
// parserOptions: {
142-
// ecmaVersion: 2018
143-
// },
144-
// globals: { stuff: false, foo: false }
145-
// },
146-
"export * as ns from \"source\"",
147-
"import.meta",
148-
"let a; class C { static {} } a;",
149-
"var a; class C { static {} } a;",
150-
"a; class C { static {} } var a;",
151-
"class C { static { C; } }",
152-
"const C = class { static { C; } }",
153-
"class C { static { a; } } var a;",
154-
"class C { static { a; } } let a;",
155-
"class C { static { var a; a; } }",
156-
"class C { static { a; var a; } }",
157-
"class C { static { a; { var a; } } }",
158-
"class C { static { let a; a; } }",
159-
"class C { static { a; let a; } }",
160-
"class C { static { function a() {} a; } }",
161-
"class C { static { a; function a() {} } }",
162-
"String;Array;Boolean;",
163-
"function resolve<T>(path: string): T { return { path } as T; }",
164-
"let xyz: NodeListOf<HTMLElement>",
165-
"type Foo = Record<string, unknown>;",
142+
("Array = 1;", None, None),
143+
("class A { constructor() { new.target; } }", None, None),
144+
(
145+
"var {bacon, ...others} = stuff; foo(others)",
146+
None,
147+
// parserOptions: {
148+
// ecmaVersion: 2018
149+
// },
150+
Some(serde_json::json!({"globals": { "stuff": false, "foo": false }})),
151+
),
152+
("export * as ns from \"source\"", None, None),
153+
("import.meta", None, None),
154+
("let a; class C { static {} } a;", None, None),
155+
("var a; class C { static {} } a;", None, None),
156+
("a; class C { static {} } var a;", None, None),
157+
("class C { static { C; } }", None, None),
158+
("const C = class { static { C; } }", None, None),
159+
("class C { static { a; } } var a;", None, None),
160+
("class C { static { a; } } let a;", None, None),
161+
("class C { static { var a; a; } }", None, None),
162+
("class C { static { a; var a; } }", None, None),
163+
("class C { static { a; { var a; } } }", None, None),
164+
("class C { static { let a; a; } }", None, None),
165+
("class C { static { a; let a; } }", None, None),
166+
("class C { static { function a() {} a; } }", None, None),
167+
("class C { static { a; function a() {} } }", None, None),
168+
("String;Array;Boolean;", None, None),
169+
("[Float16Array, Iterator]", None, None), // es2025
170+
// ("AsyncDisposableStack; DisposableStack; SuppressedError", None, None), / es2026
171+
("function resolve<T>(path: string): T { return { path } as T; }", None, None),
172+
("let xyz: NodeListOf<HTMLElement>", None, None),
173+
("type Foo = Record<string, unknown>;", None, None),
166174
];
167175

168176
let fail = vec![
169-
"a = 1;",
170-
"var a = b;",
171-
"function f() { b; }",
172-
"window;",
173-
"require(\"a\");",
174-
"var React; React.render(<img attr={a} />);",
175-
"var React, App; React.render(<App attr={a} />);",
176-
"[a] = [0];",
177-
"({a} = {});",
178-
"({b: a} = {});",
179-
"[obj.a, obj.b] = [0, 1];",
180-
"const c = 0; const a = {...b, c};",
181-
"class C { static { a; } }",
182-
"class C { static { { let a; } a; } }",
183-
"class C { static { { function a() {} } a; } }",
184-
"class C { static { function foo() { var a; } a; } }",
185-
"class C { static { var a; } static { a; } }",
186-
"class C { static { let a; } static { a; } }",
187-
"class C { static { function a(){} } static { a; } }",
188-
"class C { static { var a; } foo() { a; } }",
189-
"class C { static { let a; } foo() { a; } }",
190-
"class C { static { var a; } [a]; }",
191-
"class C { static { let a; } [a]; }",
192-
"class C { static { function a() {} } [a]; }",
193-
"class C { static { var a; } } a;",
194-
"toString()",
195-
"hasOwnProperty()",
177+
("a = 1;", None, None),
178+
// ("if (typeof anUndefinedVar === 'string') {}", Some(serde_json::json!({"typeof": true})), None), // should fail on `anUndefinedVar`
179+
("var a = b;", None, None),
180+
("function f() { b; }", None, None),
181+
("window;", None, None),
182+
// ("Intl;", None, None), builtin
183+
("require(\"a\");", None, None),
184+
("var React; React.render(<img attr={a} />);", None, None),
185+
("var React, App; React.render(<App attr={a} />);", None, None),
186+
("[a] = [0];", None, None),
187+
("({a} = {});", None, None),
188+
("({b: a} = {});", None, None),
189+
("[obj.a, obj.b] = [0, 1];", None, None),
190+
("const c = 0; const a = {...b, c};", None, None),
191+
("class C { static { a; } }", None, None),
192+
("class C { static { { let a; } a; } }", None, None),
193+
("class C { static { { function a() {} } a; } }", None, None),
194+
("class C { static { function foo() { var a; } a; } }", None, None),
195+
("class C { static { var a; } static { a; } }", None, None),
196+
("class C { static { let a; } static { a; } }", None, None),
197+
("class C { static { function a(){} } static { a; } }", None, None),
198+
("class C { static { var a; } foo() { a; } }", None, None),
199+
("class C { static { let a; } foo() { a; } }", None, None),
200+
("class C { static { var a; } [a]; }", None, None),
201+
("class C { static { let a; } [a]; }", None, None),
202+
("class C { static { function a() {} } [a]; }", None, None),
203+
("class C { static { var a; } } a;", None, None),
204+
("toString()", None, None),
205+
("hasOwnProperty()", None, None),
196206
];
197207

198208
Tester::new(NoUndef::NAME, NoUndef::PLUGIN, pass, fail).test_and_snapshot();

0 commit comments

Comments
 (0)