Skip to content

Commit

Permalink
new-for-builtins...
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed May 10, 2024
1 parent 3da4fc4 commit 437a335
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 87 deletions.
7 changes: 6 additions & 1 deletion test/new-for-builtins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ test.snapshot({
'const foo = new Number(\'123\')',
'const foo = new String()',
'const foo = new Symbol()',
`
outdent`
function varCheck() {
{
var WeakMap = function() {};
Expand All @@ -252,5 +252,10 @@ test.snapshot({
return Map()
}
`,
outdent`
function foo() {
return(globalThis).Map()
}
`
],
});
191 changes: 105 additions & 86 deletions test/snapshots/new-for-builtins.mjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1267,105 +1267,124 @@ Generated by [AVA](https://avajs.dev).
> Input
`␊
1 |␊
2 | function varCheck() {␊
3 | {␊
4 | var WeakMap = function() {};␊
5 | }␊
6 | // This should not reported␊
7 | return WeakMap()␊
8 | }␊
9 | function constCheck() {␊
10 | {␊
11 | const Array = function() {};␊
12 | }␊
13 | return Array()␊
14 | }␊
15 | function letCheck() {␊
16 | {␊
17 | let Map = function() {};␊
18 | }␊
19 | return Map()␊
20 | }␊
21 | ␊
1 | function varCheck() {␊
2 | {␊
3 | var WeakMap = function() {};␊
4 | }␊
5 | // This should not reported␊
6 | return WeakMap()␊
7 | }␊
8 | function constCheck() {␊
9 | {␊
10 | const Array = function() {};␊
11 | }␊
12 | return Array()␊
13 | }␊
14 | function letCheck() {␊
15 | {␊
16 | let Map = function() {};␊
17 | }␊
18 | return Map()␊
19 | }␊
`

> Output
`␊
1 |␊
2 | function varCheck() {␊
3 | {␊
4 | var WeakMap = function() {};␊
5 | }␊
6 | // This should not reported␊
7 | return WeakMap()␊
8 | }␊
9 | function constCheck() {␊
10 | {␊
11 | const Array = function() {};␊
12 | }␊
13 | return new Array()␊
14 | }␊
15 | function letCheck() {␊
16 | {␊
17 | let Map = function() {};␊
18 | }␊
19 | return new Map()␊
20 | }␊
21 | ␊
1 | function varCheck() {␊
2 | {␊
3 | var WeakMap = function() {};␊
4 | }␊
5 | // This should not reported␊
6 | return WeakMap()␊
7 | }␊
8 | function constCheck() {␊
9 | {␊
10 | const Array = function() {};␊
11 | }␊
12 | return new Array()␊
13 | }␊
14 | function letCheck() {␊
15 | {␊
16 | let Map = function() {};␊
17 | }␊
18 | return new Map()␊
19 | }␊
`

> Error 1/2
`␊
1 |␊
2 | function varCheck() {␊
3 | {␊
4 | var WeakMap = function() {};␊
5 | }␊
6 | // This should not reported␊
7 | return WeakMap()␊
8 | }␊
9 | function constCheck() {␊
10 | {␊
11 | const Array = function() {};␊
12 | }␊
> 13 | return Array()␊
| ^^^^^^^ Use \`new Array()\` instead of \`Array()\`.␊
14 | }␊
15 | function letCheck() {␊
16 | {␊
17 | let Map = function() {};␊
18 | }␊
19 | return Map()␊
20 | }␊
21 | ␊
1 | function varCheck() {␊
2 | {␊
3 | var WeakMap = function() {};␊
4 | }␊
5 | // This should not reported␊
6 | return WeakMap()␊
7 | }␊
8 | function constCheck() {␊
9 | {␊
10 | const Array = function() {};␊
11 | }␊
> 12 | return Array()␊
| ^^^^^^^ Use \`new Array()\` instead of \`Array()\`.␊
13 | }␊
14 | function letCheck() {␊
15 | {␊
16 | let Map = function() {};␊
17 | }␊
18 | return Map()␊
19 | }␊
`

> Error 2/2
`␊
1 |␊
2 | function varCheck() {␊
3 | {␊
4 | var WeakMap = function() {};␊
5 | }␊
6 | // This should not reported␊
7 | return WeakMap()␊
8 | }␊
9 | function constCheck() {␊
10 | {␊
11 | const Array = function() {};␊
12 | }␊
13 | return Array()␊
14 | }␊
15 | function letCheck() {␊
16 | {␊
17 | let Map = function() {};␊
18 | }␊
> 19 | return Map()␊
| ^^^^^ Use \`new Map()\` instead of \`Map()\`.␊
20 | }␊
21 | ␊
1 | function varCheck() {␊
2 | {␊
3 | var WeakMap = function() {};␊
4 | }␊
5 | // This should not reported␊
6 | return WeakMap()␊
7 | }␊
8 | function constCheck() {␊
9 | {␊
10 | const Array = function() {};␊
11 | }␊
12 | return Array()␊
13 | }␊
14 | function letCheck() {␊
15 | {␊
16 | let Map = function() {};␊
17 | }␊
> 18 | return Map()␊
| ^^^^^ Use \`new Map()\` instead of \`Map()\`.␊
19 | }␊
`

## invalid(60): function foo() { return(globalThis).Map() }

> Input
`␊
1 | function foo() {␊
2 | return(globalThis).Map()␊
3 | }␊
`

> Output
`␊
1 | function foo() {␊
2 | returnnew (globalThis).Map()␊
3 | }␊
`

> Error 1/1
`␊
1 | function foo() {␊
> 2 | return(globalThis).Map()␊
| ^^^^^^^^^^^^^^^^^^ Use \`new Map()\` instead of \`Map()\`.␊
3 | }␊
`
Binary file modified test/snapshots/new-for-builtins.mjs.snap
Binary file not shown.

0 comments on commit 437a335

Please sign in to comment.