Skip to content

Commit feb0ab7

Browse files
committed
update tests
1 parent 07ff4b7 commit feb0ab7

12 files changed

+487
-4
lines changed

Diff for: tests/baselines/reference/elidedJSImport1.errors.txt

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tests/cases/compiler/caller.js(1,21): error TS2307: Cannot find module 'fs' or its corresponding type declarations.
2+
tests/cases/compiler/caller.js(2,8): error TS18042: 'TruffleContract' is a type and cannot be imported in JavaScript files. Use 'import("@truffle/contract").TruffleContract' in a JSDoc type annotation.
3+
tests/cases/compiler/caller.js(4,43): error TS2708: Cannot use namespace 'TruffleContract' as a value.
4+
tests/cases/compiler/caller.js(4,60): error TS2708: Cannot use namespace 'TruffleContract' as a value.
5+
6+
7+
==== tests/cases/compiler/caller.js (4 errors) ====
8+
import * as fs from 'fs';
9+
~~~~
10+
!!! error TS2307: Cannot find module 'fs' or its corresponding type declarations.
11+
import TruffleContract from '@truffle/contract'; // Runtime err: this import is elided in transform
12+
~~~~~~~~~~~~~~~
13+
!!! error TS18042: 'TruffleContract' is a type and cannot be imported in JavaScript files. Use 'import("@truffle/contract").TruffleContract' in a JSDoc type annotation.
14+
console.log(fs);
15+
console.log('TruffleContract is ', typeof TruffleContract, TruffleContract); // `TruffleContract` is considered 'unused'
16+
~~~~~~~~~~~~~~~
17+
!!! error TS2708: Cannot use namespace 'TruffleContract' as a value.
18+
~~~~~~~~~~~~~~~
19+
!!! error TS2708: Cannot use namespace 'TruffleContract' as a value.
20+
21+
22+
==== tests/cases/compiler/node_modules/@truffle/contract/index.d.ts (0 errors) ====
23+
declare module "@truffle/contract" {
24+
interface ContractObject {
25+
foo: number;
26+
}
27+
namespace TruffleContract {
28+
export type Contract = ContractObject;
29+
}
30+
export default TruffleContract;
31+
}

Diff for: tests/baselines/reference/elidedJSImport1.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/elidedJSImport1.ts] ////
2+
3+
//// [caller.js]
4+
import * as fs from 'fs';
5+
import TruffleContract from '@truffle/contract'; // Runtime err: this import is elided in transform
6+
console.log(fs);
7+
console.log('TruffleContract is ', typeof TruffleContract, TruffleContract); // `TruffleContract` is considered 'unused'
8+
9+
10+
//// [index.d.ts]
11+
declare module "@truffle/contract" {
12+
interface ContractObject {
13+
foo: number;
14+
}
15+
namespace TruffleContract {
16+
export type Contract = ContractObject;
17+
}
18+
export default TruffleContract;
19+
}
20+
21+
//// [caller.js]
22+
import * as fs from 'fs';
23+
import TruffleContract from '@truffle/contract'; // Runtime err: this import is elided in transform
24+
console.log(fs);
25+
console.log('TruffleContract is ', typeof TruffleContract, TruffleContract); // `TruffleContract` is considered 'unused'

Diff for: tests/baselines/reference/elidedJSImport1.symbols

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== tests/cases/compiler/caller.js ===
2+
import * as fs from 'fs';
3+
>fs : Symbol(fs, Decl(caller.js, 0, 6))
4+
5+
import TruffleContract from '@truffle/contract'; // Runtime err: this import is elided in transform
6+
>TruffleContract : Symbol(TruffleContract, Decl(caller.js, 1, 6))
7+
8+
console.log(fs);
9+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
10+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
11+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
12+
>fs : Symbol(fs, Decl(caller.js, 0, 6))
13+
14+
console.log('TruffleContract is ', typeof TruffleContract, TruffleContract); // `TruffleContract` is considered 'unused'
15+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
16+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
17+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
18+
19+
20+
=== tests/cases/compiler/node_modules/@truffle/contract/index.d.ts ===
21+
declare module "@truffle/contract" {
22+
>"@truffle/contract" : Symbol("@truffle/contract", Decl(index.d.ts, 0, 0))
23+
24+
interface ContractObject {
25+
>ContractObject : Symbol(ContractObject, Decl(index.d.ts, 0, 36))
26+
27+
foo: number;
28+
>foo : Symbol(ContractObject.foo, Decl(index.d.ts, 1, 30))
29+
}
30+
namespace TruffleContract {
31+
>TruffleContract : Symbol(TruffleContract, Decl(index.d.ts, 3, 5))
32+
33+
export type Contract = ContractObject;
34+
>Contract : Symbol(Contract, Decl(index.d.ts, 4, 31))
35+
>ContractObject : Symbol(ContractObject, Decl(index.d.ts, 0, 36))
36+
}
37+
export default TruffleContract;
38+
>TruffleContract : Symbol(TruffleContract, Decl(index.d.ts, 3, 5))
39+
}

Diff for: tests/baselines/reference/elidedJSImport1.types

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
=== tests/cases/compiler/caller.js ===
2+
import * as fs from 'fs';
3+
>fs : any
4+
5+
import TruffleContract from '@truffle/contract'; // Runtime err: this import is elided in transform
6+
>TruffleContract : any
7+
8+
console.log(fs);
9+
>console.log(fs) : void
10+
>console.log : (...data: any[]) => void
11+
>console : Console
12+
>log : (...data: any[]) => void
13+
>fs : any
14+
15+
console.log('TruffleContract is ', typeof TruffleContract, TruffleContract); // `TruffleContract` is considered 'unused'
16+
>console.log('TruffleContract is ', typeof TruffleContract, TruffleContract) : void
17+
>console.log : (...data: any[]) => void
18+
>console : Console
19+
>log : (...data: any[]) => void
20+
>'TruffleContract is ' : "TruffleContract is "
21+
>typeof TruffleContract : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
22+
>TruffleContract : any
23+
>TruffleContract : any
24+
25+
26+
=== tests/cases/compiler/node_modules/@truffle/contract/index.d.ts ===
27+
declare module "@truffle/contract" {
28+
>"@truffle/contract" : typeof import("@truffle/contract")
29+
30+
interface ContractObject {
31+
foo: number;
32+
>foo : number
33+
}
34+
namespace TruffleContract {
35+
export type Contract = ContractObject;
36+
>Contract : ContractObject
37+
}
38+
export default TruffleContract;
39+
>TruffleContract : any
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//// [tests/cases/compiler/elidedJSImport2.ts] ////
2+
3+
//// [index.js]
4+
import { Foo } from "./other.js";
5+
import * as other from "./other.js";
6+
import defaultFoo from "./other.js";
7+
8+
const x = new Foo();
9+
const y = other.Foo();
10+
const z = new defaultFoo();
11+
12+
//// [other.d.ts]
13+
export interface Foo {
14+
bar: number;
15+
}
16+
17+
export default interface Bar {
18+
foo: number;
19+
}
20+
21+
//// [other.js]
22+
export class Foo {
23+
bar = 2.4;
24+
}
25+
26+
export default class Bar {
27+
foo = 1.2;
28+
}
29+
30+
31+
//// [index.js]
32+
"use strict";
33+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
34+
if (k2 === undefined) k2 = k;
35+
var desc = Object.getOwnPropertyDescriptor(m, k);
36+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
37+
desc = { enumerable: true, get: function() { return m[k]; } };
38+
}
39+
Object.defineProperty(o, k2, desc);
40+
}) : (function(o, m, k, k2) {
41+
if (k2 === undefined) k2 = k;
42+
o[k2] = m[k];
43+
}));
44+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
45+
Object.defineProperty(o, "default", { enumerable: true, value: v });
46+
}) : function(o, v) {
47+
o["default"] = v;
48+
});
49+
var __importStar = (this && this.__importStar) || function (mod) {
50+
if (mod && mod.__esModule) return mod;
51+
var result = {};
52+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
53+
__setModuleDefault(result, mod);
54+
return result;
55+
};
56+
var __importDefault = (this && this.__importDefault) || function (mod) {
57+
return (mod && mod.__esModule) ? mod : { "default": mod };
58+
};
59+
exports.__esModule = true;
60+
var other_js_1 = require("./other.js");
61+
var other = __importStar(require("./other.js"));
62+
var other_js_2 = __importDefault(require("./other.js"));
63+
var x = new other_js_1.Foo();
64+
var y = other.Foo();
65+
var z = new other_js_2["default"]();
66+
//// [other.js]
67+
"use strict";
68+
exports.__esModule = true;
69+
exports.Foo = void 0;
70+
var Foo = /** @class */ (function () {
71+
function Foo() {
72+
this.bar = 2.4;
73+
}
74+
return Foo;
75+
}());
76+
exports.Foo = Foo;
77+
var Bar = /** @class */ (function () {
78+
function Bar() {
79+
this.foo = 1.2;
80+
}
81+
return Bar;
82+
}());
83+
exports["default"] = Bar;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
=== tests/cases/compiler/index.js ===
2+
import { Foo } from "./other.js";
3+
>Foo : Symbol(Foo, Decl(index.js, 0, 8))
4+
5+
import * as other from "./other.js";
6+
>other : Symbol(other, Decl(index.js, 1, 6))
7+
8+
import defaultFoo from "./other.js";
9+
>defaultFoo : Symbol(defaultFoo, Decl(index.js, 2, 6))
10+
11+
const x = new Foo();
12+
>x : Symbol(x, Decl(index.js, 4, 5))
13+
14+
const y = other.Foo();
15+
>y : Symbol(y, Decl(index.js, 5, 5))
16+
>other : Symbol(other, Decl(index.js, 1, 6))
17+
18+
const z = new defaultFoo();
19+
>z : Symbol(z, Decl(index.js, 6, 5))
20+
21+
=== tests/cases/compiler/other.d.ts ===
22+
export interface Foo {
23+
>Foo : Symbol(Foo, Decl(other.d.ts, 0, 0))
24+
25+
bar: number;
26+
>bar : Symbol(Foo.bar, Decl(other.d.ts, 0, 22))
27+
}
28+
29+
export default interface Bar {
30+
>Bar : Symbol(Bar, Decl(other.d.ts, 2, 1))
31+
32+
foo: number;
33+
>foo : Symbol(Bar.foo, Decl(other.d.ts, 4, 30))
34+
}
35+
36+
=== tests/cases/compiler/other.js ===
37+
export class Foo {
38+
>Foo : Symbol(Foo, Decl(other.js, 0, 0))
39+
40+
bar = 2.4;
41+
>bar : Symbol(Foo.bar, Decl(other.js, 0, 18))
42+
}
43+
44+
export default class Bar {
45+
>Bar : Symbol(Bar, Decl(other.js, 2, 1))
46+
47+
foo = 1.2;
48+
>foo : Symbol(Bar.foo, Decl(other.js, 4, 26))
49+
}
50+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
=== tests/cases/compiler/index.js ===
2+
import { Foo } from "./other.js";
3+
>Foo : any
4+
5+
import * as other from "./other.js";
6+
>other : typeof other
7+
8+
import defaultFoo from "./other.js";
9+
>defaultFoo : any
10+
11+
const x = new Foo();
12+
>x : error
13+
>new Foo() : error
14+
>Foo : error
15+
16+
const y = other.Foo();
17+
>y : error
18+
>other.Foo() : error
19+
>other.Foo : error
20+
>other : typeof other
21+
>Foo : any
22+
23+
const z = new defaultFoo();
24+
>z : error
25+
>new defaultFoo() : error
26+
>defaultFoo : error
27+
28+
=== tests/cases/compiler/other.d.ts ===
29+
export interface Foo {
30+
bar: number;
31+
>bar : number
32+
}
33+
34+
export default interface Bar {
35+
foo: number;
36+
>foo : number
37+
}
38+
39+
=== tests/cases/compiler/other.js ===
40+
export class Foo {
41+
>Foo : Foo
42+
43+
bar = 2.4;
44+
>bar : number
45+
>2.4 : 2.4
46+
}
47+
48+
export default class Bar {
49+
>Bar : Bar
50+
51+
foo = 1.2;
52+
>foo : number
53+
>1.2 : 1.2
54+
}
55+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//// [tests/cases/compiler/elidedJSImport2.ts] ////
2+
3+
//// [index.js]
4+
import { Foo } from "./other.js";
5+
import * as other from "./other.js";
6+
import defaultFoo from "./other.js";
7+
8+
const x = new Foo();
9+
const y = other.Foo();
10+
const z = new defaultFoo();
11+
12+
//// [other.d.ts]
13+
export interface Foo {
14+
bar: number;
15+
}
16+
17+
export default interface Bar {
18+
foo: number;
19+
}
20+
21+
//// [other.js]
22+
export class Foo {
23+
bar = 2.4;
24+
}
25+
26+
export default class Bar {
27+
foo = 1.2;
28+
}
29+
30+
31+
//// [index.js]
32+
import { Foo } from "./other.js";
33+
import * as other from "./other.js";
34+
import defaultFoo from "./other.js";
35+
var x = new Foo();
36+
var y = other.Foo();
37+
var z = new defaultFoo();
38+
//// [other.js]
39+
var Foo = /** @class */ (function () {
40+
function Foo() {
41+
this.bar = 2.4;
42+
}
43+
return Foo;
44+
}());
45+
export { Foo };
46+
var Bar = /** @class */ (function () {
47+
function Bar() {
48+
this.foo = 1.2;
49+
}
50+
return Bar;
51+
}());
52+
export default Bar;

0 commit comments

Comments
 (0)